diff --git a/swh/objstorage/backends/azure.py b/swh/objstorage/backends/azure.py index be7aeaa..80d8fba 100644 --- a/swh/objstorage/backends/azure.py +++ b/swh/objstorage/backends/azure.py @@ -78,12 +78,23 @@ def get_container_url( def call_async(f, *args): """Calls an async coroutine from a synchronous function.""" + # if called from another async function (eg. gunicorn), we need to temporarily + # disable it. + # FIXME: the right fix would be either: + # * to use async in the whole stack, or + # * use a threaded server instead of an async server + # because doing it this way blocks the whole server while serving the request. + parent_loop = asyncio.events._get_running_loop() + asyncio.events._set_running_loop(None) + loop = asyncio.new_event_loop() + assert asyncio.events._get_running_loop() is None try: return loop.run_until_complete(f(*args)) finally: loop.run_until_complete(loop.shutdown_asyncgens()) loop.close() + asyncio.events._set_running_loop(parent_loop) class AzureCloudObjStorage(ObjStorage):