Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add a new internal thread safe handle for asyncio #128340

Closed
@kumaraditya303

Description

@kumaraditya303

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

Footnotes

  1. https://docs.python.org/3.13/library/asyncio-eventloop.html#asyncio.loop.call_soon_threadsafe

  2. https://docs.python.org/3.13/library/asyncio-eventloop.html#asyncio.Handle

  3. https://docs.python.org/3.13/library/asyncio-eventloop.html#asyncio.Handle.cancel

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp