[issue44508] asyncio: document failure mode for loop.call_soon_threadsafe
New submission from Mark Dickinson <dickinsm@gmail.com>: `loop.call_soon_threadsafe` raises `RuntimeError` when the event loop has been closed, but that fact doesn't seem to be documented. It would be useful to document it so that that it's clear that that behaviour is part of the API, and can be depended on. Doc link: I'm looking at https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_s... My use-case is that I have a background thread that's making use of `loop.call_soon_threadsafe` to place callbacks onto the main thread's event loop. The main thread at some point closes that event loop (e.g., as part of controlled application shutdown, or in the tearDown of a unit test). The background thread isn't in a position to know whether the event loop has been closed or not, and obviously checking that using the `is_closed` attribute runs into race condition issues. So I'd like to catch the potential exception from the `loop.call_soon_threadsafe`, but to do that I need to know what exception type to catch. It would probably also make sense to document the failure mode for `loop.call_soon`. ---------- assignee: docs@python components: Documentation, asyncio messages: 396523 nosy: asvetlov, docs@python, mark.dickinson, yselivanov priority: normal severity: normal status: open title: asyncio: document failure mode for loop.call_soon_threadsafe versions: Python 3.10, Python 3.11, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
Change by meowmeowcat <meowmeowcat1211@gmail.com>: ---------- keywords: +patch nosy: +meowmeowmeowcat nosy_count: 4.0 -> 5.0 pull_requests: +26174 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27688 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
meowmeowcat <meowmeowcat1211@gmail.com> added the comment: Thanks! I've opened a PR for this issue. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
Łukasz Langa <lukasz@langa.pl> added the comment: New changeset 3240bc62f4e0afa09964f3afc845697f0a0806b9 by meowmeowmeowcat in branch 'main': bpo-44508: [Doc] Document failure mode for loop.call_soon_threadsafe (GH-27688) https://github.com/python/cpython/commit/3240bc62f4e0afa09964f3afc845697f0a0... ---------- nosy: +lukasz.langa _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- nosy: +miss-islington nosy_count: 6.0 -> 7.0 pull_requests: +26270 pull_request: https://github.com/python/cpython/pull/27804 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +26271 pull_request: https://github.com/python/cpython/pull/27805 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset bbb10761b64095425f7f8dcb3bc1f0d8bdee528a by Miss Islington (bot) in branch '3.10': bpo-44508: [Doc] Document failure mode for loop.call_soon_threadsafe (GH-27688) https://github.com/python/cpython/commit/bbb10761b64095425f7f8dcb3bc1f0d8bde... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
Łukasz Langa <lukasz@langa.pl> added the comment: New changeset e2320c6a34d44a0efa7ecc693c3a6215014b7b6e by Miss Islington (bot) in branch '3.9': bpo-44508: [Doc] Document failure mode for loop.call_soon_threadsafe (GH-27688) (GH-27805) https://github.com/python/cpython/commit/e2320c6a34d44a0efa7ecc693c3a6215014... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
Łukasz Langa <lukasz@langa.pl> added the comment: Thanks for reporting, Mark, and for the patch, meowmeowcat! ✨ 🍰 ✨ ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue44508> _______________________________________
participants (4)
-
Mark Dickinson -
meowmeowcat -
miss-islington -
Łukasz Langa