Boost error when trying to use gr.msg_queue.delete_head_nowait()

I’m trying to use gr.msg_queue.delete_head_nowait() in a python example,
and if I use delete_head_nowait I get this error:

python: /usr/include/boost/smart_ptr/shared_ptr.hpp:418: T*
boost::shared_ptr< >::operator->() const [with
T =
gr_message]: Assertion `px != 0’ failed.
Aborted

The blocking version of delete_head works fine.

Here’s the code:

while self.keep_running:
msg = self.rcvd_pktq.delete_head_nowait()
if msg:
result = packet_utils2.unmake_packet(msg.to_string(),
int(msg.arg1()))
else:
if len(packet_utils2.uncoded) > 0:
result = packet_utils2.unmake_packet(None)

        if result: #make sure it's not null

            ok, payload = result
            m = msg.to_string()

print ‘payload"’, m