Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P1303
objstorage async in sync in async
Active
Public
Actions
Authored by
vlorentz
on Feb 28 2022, 5:06 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
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):
Event Timeline
vlorentz
created this paste.
Feb 28 2022, 5:06 PM
2022-02-28 17:06:11 (UTC+1)
vlorentz
updated the paste's language from
python
to
diff
.
Log In to Comment