Skip to content

0.1.0

Latest

Choose a tag to compare

@github-actions github-actions released this 05 Nov 20:34
· 3 commits to main since this release
275267a

The first release of Pyjo-Reactor-Winloop: a reactor for Pyjoyment that runs on Winloop, the fork of uvloop for Windows, the asyncio event loop built on libuv. With it, the servers of Pyjoyment on Windows (daemon and prethread, as Windows has no fork for prefork) and the blocking requests of its user agent run on Winloop, and coroutines, tasks and asyncio libraries run alongside them. It ships as a separate distribution, like every Pyjoyment reactor with a dependency, because Pyjoyment itself has no runtime dependencies. It requires Pyjoyment 0.3.0 and Winloop 0.8.2 or later.

pip install Pyjo-Reactor-Winloop
uv add Pyjo-Reactor-Winloop

PYJO_REACTOR selects it for Pyjo.IOLoop, the same way as the reactors of Pyjoyment, so an application needs no changes. In PowerShell:

$env:PYJO_REACTOR = 'Pyjo.Reactor.Winloop'
python myapp.py daemon
python myapp.py prethread

The reactor: Pyjo.Reactor.Winloop

  • Pyjo.Reactor.Asyncio with its own Winloop loop. When the reactor creates a loop for itself, that loop is a Winloop loop instead of the asyncio.SelectorEventLoop that Pyjo.Reactor.Asyncio creates on Windows. When it is given a loop, or one is already running (for example inside asyncio.run), the reactor uses that loop, as Pyjo.Reactor.Asyncio does. An ASGI server that runs a Winloop loop itself, for example with loop_factory=winloop.new_event_loop, already runs Pyjoyment on Winloop with the default reactor.
  • Sockets without the limit of select. libuv polls sockets with the I/O completion ports of Windows, without the limit of 512 sockets of select.select. As with the asyncio.SelectorEventLoop of Windows, only sockets can be watched, not pipes or files.
  • Workers of prethread take turns with a shared socket. libuv of Windows polls a socket for one loop at a time, so loops in threads that watch the same socket, as the workers of Pyjo.Server.Prethread watch the listen sockets of the manager, polled it in a busy loop: four idle workers took about 250% of the processors. The reactor hands the socket over from one loop to the next after each of its events, so idle workers take no processor time and the connections go to every worker in turn (#5).
  • Winloop behaves like the asyncio loop wherever Pyjoyment depends on it:
    • A stop from an I/O callback ends the run without another round of I/O events. Without the fix, an event that stopped the reactor or ended one_tick would be followed by the same events again.
    • A timer, including asyncio.sleep, never fires before its time. libuv counts whole milliseconds and could fire up to 1 ms early; now a timer may be up to 2 ms late instead. The same fix for uvloop is in MagicStack/uvloop#755, which is not released yet.
    • In the asyncio debug mode (PYTHONDEVMODE=1), async generators are finalized with the hook of asyncio, not the one of Winloop, which it shares with uvloop, where it crashes CPython (MagicStack/uvloop#756, not released yet).
  • Signals. A Python signal handler runs while the loop waits, so Ctrl-C and Ctrl-Break stop a server. A wakeup fd that the program sets with signal.set_wakeup_fd is not written to while the reactor's own loop runs in the main thread, because Winloop sets its own.
  • PYJO_ASYNCIO_SLOW_CALLBACK sets slow_callback_duration of the reactor's own loop, as for Pyjo.Reactor.Asyncio.

Tests

The whole test suite of Pyjoyment 0.3.0 passes on the reactor on Windows, since a reactor must pass all of it. t/Reactor_Winloop.py is t/Pyjo/Reactor_Asyncio.py of Pyjoyment (the port of t/mojo/reactor_poll.t of Mojolicious 9.53), plus subtests for each Winloop difference above and for a socket that reactors in threads watch. CI runs both with PYTHONDEVMODE=1 on Windows Server 2025.

Examples and documentation

  • examples/hello_world_winloop.py: Pyjo.HelloWorld on the Pyjoyment server on Winloop, until Ctrl-C or Ctrl-Break.
  • examples/asyncio_winloop.py: a coroutine on the Winloop loop that requests the Pyjoyment server in the same loop, once with asyncio streams and once with the Pyjoyment user agent.
  • examples/loopback_winloop.py: a Pyjoyment server and a blocking request of its user agent on the Winloop loop.
  • The documentation covers the module's API and the examples, as a subproject of the Pyjoyment documentation.

Platforms

CPython 3.12 to 3.15 and the free-threaded build of 3.15, on Windows x64 and ARM64, where Winloop has wheels. Tested on x64 in CI and on ARM64. PyPy, Linux and macOS are not supported: Winloop runs only on Windows, and on Linux and macOS Pyjo-Reactor-Uvloop runs Pyjoyment on uvloop.

Supply chain

The wheel and the sdist come with an SBOM in SPDX format of the distribution and its dependencies, and with attestations of their build provenance:

gh attestation verify pyjo_reactor_winloop-0.1.0.tar.gz -R pyjoyment/Pyjo-Reactor-Winloop

They are published to PyPI with trusted publishing and PEP 740 attestations.

Full Changelog: https://github.com/pyjoyment/Pyjo-Reactor-Winloop/commits/0.1.0