Skip to content

event_loop_modules of Pyjo.Reactor, so that finalizers defer their cleanups below the frames of the event loop #7

Closed

Description

@dex4er

The change in Pyjoyment

Pyjo.Reactor._finalize defers the cleanup of a finalizer that the garbage collector runs in the middle of the code of a reactor or of its event loop, so that closing a stream or removing an acceptor does not change the structures that the reactor or the event loop are changing. Since pyjoyment/Pyjoyment#534 (pyjoyment/Pyjoyment#533), it finds those frames:

  • in the files of the modules of the classes of the reactors, wherever they are installed, also editable, as in development and in the workflow Tests, where Pyjo/Reactor/Uvloop.py of this repository is not next to the reactors of Pyjoyment;
  • in the loaded modules that the new class attribute event_loop_modules names, a package as its directory, a module as its file.

Pyjo.Reactor.Asyncio names ('asyncio', 'selectors') there, which _prefixes() had hard-coded before.

What to do here

  • Pyjo_Reactor_Uvloop inherits ('asyncio', 'selectors') from Pyjo.Reactor.Asyncio, and Pyjo/Reactor/Uvloop.py, with _Loop, is covered as the module of the class. The loop of uvloop is compiled with Cython and has no frames of Python, so there may be nothing to name: check whether a callback of the reactor runs below a frame of the Python modules of uvloop, and if it does, extend the attribute, as event_loop_modules = (*Pyjo.Reactor.Asyncio.object.event_loop_modules, 'uvloop').

  • Test it with the suite of Pyjoyment on this reactor with PYTHONDEVMODE=1, t/stdlib/IOLoop_gc.py above all, and with PyPy, whose garbage collector runs anywhere.

  • The attribute is harmless on Pyjoyment 0.2.0, which ignores it, but the frames are deferred only with a Pyjoyment that has Pyjo.Reactor: event_loop_modules, and finalizers deferred below the frames of a reactor of another distribution or of its event loop Pyjoyment#534: uv lock --upgrade-package pyjoyment takes it from the branch main of the git source.

Activity

  1. dex4er commented on Nov 5, 2026

    @dex4er
    ContributorAuthor

    Checked, nothing to name: event_loop_modules stays the inherited ('asyncio', 'selectors'), with Pyjo/Reactor/Uvloop.py and its _Loop covered as the module of the class.

    • A probe of Pyjo.Reactor._finalize (through sitecustomize) recorded the stack of every call over the whole suite of Pyjoyment b6d623e on the reactor with PYTHONDEVMODE=1: 4265 calls in 198 processes, t/stdlib/IOLoop_gc.py among them, and no frame of the directory of uvloop nor of a .pyx below any of them. The loop of uvloop is compiled with Cython and makes no frames of Python.
    • The one place with frames of uvloop/__init__.py is the code that uvloop.run runs, its run and wrapper, and below them is asyncio/runners.py, which asyncio covers already, so 'uvloop' would change nothing.
    • PyPy does not apply: uvloop has no wheels for it.

    uv.lock takes Pyjoyment b6d623e with pyjoyment/Pyjoyment#534, and AGENTS.md notes the above, in #8.

  2. added this to the 0.1.0 milestone on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions