Skip to content

Commit

Permalink
Fixed #292: Use get_event_loop in class-level code
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Aug 18, 2021
1 parent b3a65e3 commit dfe87b2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion asgiref/sync.py
Expand Up @@ -328,7 +328,9 @@ class SyncToAsync:

# If they've set ASGI_THREADS, update the default asyncio executor for now
if "ASGI_THREADS" in os.environ:
loop = get_running_loop()
# We use get_event_loop here - not get_running_loop - as this will
# be run at import time, and we want to update the main thread's loop.
loop = asyncio.get_event_loop()
loop.set_default_executor(
ThreadPoolExecutor(max_workers=int(os.environ["ASGI_THREADS"]))
)
Expand Down

0 comments on commit dfe87b2

Please sign in to comment.