New submission from Mark Dickinson <dicki...@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_soon_threadsafe

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 <rep...@bugs.python.org>
<https://bugs.python.org/issue44508>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to