I am trying to send the message over channel layer, where I am using Thread to start the function continuously,
channel_layer = get_channel_layer()
async def send_data():
try:
await (channel_layer.group_send)('Live_Message_Layer', {
'type': 'send_live_message',
'value': {'live_message':json.dumps(message)}})
except:
print("Error while sending message ...\n", traceback.format_exc())
# RuntimeError: cannot schedule new futures after interpreter
# shutdown
class MyWorker(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
print('Worker is running .....')
while True:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(send_data())
loop.close()
time.sleep(0.5)
MyWorker().start()
In the above code, messages are changing every second, and sending it on channel layer. and this is deployed on the ubuntu, using daphne and gunicorn. what is exactly happening when server gets restarted everything works fine, but after some time, somehow this error occurs and after that the last message when the error start occurring, has sent over the channel layer repeatedly until I restart the server.
Thank you !!!