Skip to content

Handle stopped main event loops in async_to_sync#558

Open
davitacols wants to merge 1 commit intodjango:mainfrom
davitacols:issue-545-investigation
Open

Handle stopped main event loops in async_to_sync#558
davitacols wants to merge 1 commit intodjango:mainfrom
davitacols:issue-545-investigation

Conversation

@davitacols
Copy link
Copy Markdown

Summary

  • only reuse the threadlocal main_event_loop when it is still running
  • fall back to a new loop if that threadlocal loop has stopped but not closed
  • add a regression test covering the stopped-but-open loop case

A stopped loop can still accept call_soon_threadsafe() without ever running the scheduled task, which leaves async_to_sync() blocked waiting for a result.

Fixes #545.

Testing

  • python -m pytest -q
  • python -m mypy asgiref tests setup.py docs/conf.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested AsyncToSync and SyncToAsync results in blocking code

1 participant