safely operate in async or sync context

This commit is contained in:
chris meyers 2020-02-26 11:50:22 -05:00 committed by Ryan Petrello
parent 9e5fe7f5c6
commit 2b59af3808
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -202,13 +202,9 @@ class EventConsumer(AsyncJsonWebsocketConsumer):
def run_sync(func):
event_loop = None
try:
event_loop = asyncio.get_event_loop()
except RuntimeError:
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
return event_loop.run_until_complete(func)
event_loop = asyncio.new_event_loop()
event_loop.run_until_complete(func)
event_loop.close()
def _dump_payload(payload):