• Scaling asyncio On Free-Threaded Python

    From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python on Fri Sep 12 23:20:06 2025
    From Newsgroup: comp.lang.python

    This article <https://labs.quansight.org/blog/scaling-asyncio-on-free-threaded-python>,
    on the changes being made in Python 3.14 to allow asyncio to benefit
    from free-threading, had one part that particularly caught my eye:

    **Per-thread linked list of tasks:** Python 3.14 introduces a
    per-thread circular double linked list implementation for storing
    tasks instead of a global `WeakSet`. The linked list is
    per-thread, meaning that each thread maintains its own list of
    tasks and allows for lock-free addition and removal of tasks. Weak
    references are slow and and prone to contention. The new
    implementation removes the use of weak references entirely and
    makes tasks responsible for removing themselves from the list when
    they are done. This requires cooperation between the task's
    deallocator and the executing threads to ensure that the task is
    removed from the list before it is freed, otherwise a thread could
    try accessing an already freed task. By removing the use of weak
    references, the overhead of reference counting is eliminated
    entirely and addition/removal of a task in the list now requires
    only updating the pointers in the linked list.

    Anybody else been caught out, as they were starting out with asyncio,
    by tasks inexplicably disappearing during execution of an async
    program? And then you discovered, on rereading the docs, that it was
    up to you to keep your own strong refs to task objects, asyncio
    wouldnrCOt do it?

    And now that behaviour is changing, arguably to what it should have
    been in the first place, and not a moment too soon.
    --- Synchronet 3.21a-Linux NewsLink 1.2