mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 10:27:37 -02:30
safely operate in async or sync context
This commit is contained in:
committed by
Ryan Petrello
parent
9e5fe7f5c6
commit
2b59af3808
@@ -202,13 +202,9 @@ class EventConsumer(AsyncJsonWebsocketConsumer):
|
|||||||
|
|
||||||
|
|
||||||
def run_sync(func):
|
def run_sync(func):
|
||||||
event_loop = None
|
event_loop = asyncio.new_event_loop()
|
||||||
try:
|
event_loop.run_until_complete(func)
|
||||||
event_loop = asyncio.get_event_loop()
|
event_loop.close()
|
||||||
except RuntimeError:
|
|
||||||
event_loop = asyncio.new_event_loop()
|
|
||||||
asyncio.set_event_loop(event_loop)
|
|
||||||
return event_loop.run_until_complete(func)
|
|
||||||
|
|
||||||
|
|
||||||
def _dump_payload(payload):
|
def _dump_payload(payload):
|
||||||
|
|||||||
Reference in New Issue
Block a user