Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Closed
Description
loop.call_soon_threadsafe1 is a thread safe API to schedule callbacks from other threads however the handle returned by it i.e.asyncio.Handle2 isn't thread safe like itscancel3 method. This is an issue even with the GIL because thread switching is preemptive and is a bigger issue for free-threading builds.
Proposal
Add a new_ThreadSafeHandle which inherits fromasyncio.Handle but internally uses a mutex to avoid multiple threads cancelling and running the callback at the same time for callbacks scheduled byloop.call_soon_threadsafe API, other APIs such asloop.call_soon will continue to use the oldasyncio.Handle.
Linked PRs
- gh-128340: make asyncio.events.Handle.cancel() atomic #128347
- gh-128340: thread safe handle for
loop.call_soon_threadsafe#128369
Footnotes
Metadata
Metadata
Assignees
Projects
Status
Done