Skip to content

Commit

Permalink
Move main_event_loop and main_event_loop_pid initialization from Asyn…
Browse files Browse the repository at this point in the history
…cToSync.__init__ to AsyncToSync.__call__
  • Loading branch information
germaniuss committed Jan 19, 2024
1 parent 3f0147d commit dcabf0e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ def __init__(
self.__self__ = self.awaitable.__self__ # type: ignore[union-attr]
except AttributeError:
pass
if force_new_loop:
self.force_new_loop = force_new_loop

def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
__traceback_hide__ = True # noqa: F841

if self.force_new_loop:
# They have asked that we always run in a new sub-loop.
self.main_event_loop = None
else:
Expand All @@ -173,10 +178,7 @@ def __init__(
)
else:
self.main_event_loop = None

def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
__traceback_hide__ = True # noqa: F841


# You can't call AsyncToSync from a thread with a running event loop
try:
event_loop = asyncio.get_running_loop()
Expand Down

0 comments on commit dcabf0e

Please sign in to comment.