asgi_ipc
asgi_ipc copied to clipboard
Cannot receive on channel after restarting. Bug?
I have an issue and I am not sure if that is by design. When my program restarts it does not receive any more messages on a channel.
I prepared an example which you find further down.. At the 30th iteration I am simulating the restart of the program by simply doing this:
channel_layer_receive = None
channel_layer_receive = asgi.IPCChannelLayer(prefix="my_prefix")
After that the script keeps printing (None, None)
although it is still sending on the other channel layer.
Is that by design or a bug?
Example
import asgi_ipc as asgi
channel_layer_receive = asgi.IPCChannelLayer(prefix="my_prefix")
channel_layer_send = asgi.IPCChannelLayer(prefix="my_prefix")
i = 0
while i < 10:
i += 1
msg = "Message %s" % i
try:
channel_layer_send.send("my_channel", {"text": msg})
print("Sending %s" % msg)
except asgi.BaseChannelLayer.ChannelFull:
print("Dropped %s" % msg)
pass
print(channel_layer_receive.receive(["my_channel"]))
if i == 5:
channel_layer_receive = None
channel_layer_receive = asgi.IPCChannelLayer(prefix="my_prefix")
print("Done!")
Output
Sending Message 1
('my_channel', {'text': 'Message 1'})
Sending Message 2
('my_channel', {'text': 'Message 2'})
Sending Message 3
('my_channel', {'text': 'Message 3'})
Sending Message 4
('my_channel', {'text': 'Message 4'})
Sending Message 5
('my_channel', {'text': 'Message 5'})
Sending Message 6
(None, None)
Sending Message 7
(None, None)
Sending Message 8
(None, None)
Sending Message 9
(None, None)
Sending Message 10
(None, None)
Done!
Exception ignored in: <bound method MemoryDict.__del__ of <asgi_ipc.MemoryDict object at 0x7f59a875c390>>
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/asgi_ipc.py", line 311, in __del__
posix_ipc.ExistentialError: No shared memory exists with the specified name
Exception ignored in: <bound method MemoryDict.__del__ of <asgi_ipc.MemoryDict object at 0x7f59a88a6748>>
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/asgi_ipc.py", line 311, in __del__
posix_ipc.ExistentialError: No shared memory exists with the specified name