2022-03-18 08:34:10 +01:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
2022-05-03 03:58:44 +02:00
|
|
|
class NoAutoCreateEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
|
2022-03-18 08:34:10 +01:00
|
|
|
"""
|
|
|
|
By default asyncio.get_event_loop() automatically creates an event
|
|
|
|
loop for the main thread if one isn't currently installed. Since
|
|
|
|
Django intentionally uninstalls the event loop within
|
|
|
|
sync_to_async, that autocreation proliferates confusing extra
|
|
|
|
event loops that will never be run. It is also deprecated in
|
|
|
|
Python 3.10. This policy disables it so we don't rely on it by
|
|
|
|
accident.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get_event_loop(self) -> asyncio.AbstractEventLoop: # nocoverage
|
|
|
|
return asyncio.get_running_loop()
|