Skip to content

Pyjo.Reactor.Winloop: a socket that loops watch, polled by one at a time, and a timer not due before its time - #6

Merged
dex4er merged 4 commits into
mainfrom
shared-sockets
Nov 5, 2026
Merged

dex4er merged 4 commits into
mainfrom
shared-sockets

Conversation

@dex4er

@dex4er dex4er commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Loops of Winloop that watch one socket, as the workers of Pyjo.Server.Prethread watch the listen sockets of the manager on Windows, polled it in a busy loop, which starved the process and the tests next to it: the hangs of t/Pyjo/Server_Prethread.py, t/Pyjo/Server_FastCGI.py and t/Pyjo/Server_Lambda.py of Pyjoyment on the reactor, on 3.15t in CI.

Closes #5

Changes

Measurements

On Windows 11 ARM64, 4 loops in threads that watch one listen socket, idle for 2 seconds, then 40 connections:

CPU idle accepted by loop
winloop.Loop 249% 9, 9, 8, 14
_Loop of this change 0-1% 10, 10, 10, 10

t/Pyjo/Server_Prethread.py of Pyjoyment, 4 copies at once, PYTHONDEVMODE=1:

before after
3.15t 19 of 20 fail or hang 0 of 20
3.15 6 of 12 0 of 20

Validation

  • t/ of the repository with PYTHONDEVMODE=1, on 3.12, 3.15 and 3.15t; the new subtests fail without their changes
  • The suite of Pyjoyment 7b09754 on the reactor with PYTHONDEVMODE=1, -j 4, on 3.15 and on 3.15t: 434 files, 7020 tests pass
  • ruff and pyright of .trunk/trunk.yaml; Biome does not run on this machine, Trunk Check of CI checks AGENTS.md
  • t/ of the repository with Pyjoyment 7b09754 of uv.lock
  • CI: Tests. Capture the standard error and Timeout of t/Pyjo/Prove.py may still fail now and then, a process of the script not killed on the runner (Tests on Windows: a stream whose peer aborted the connection, and Pyjo.Prove before Python 3.15 Pyjoyment#545)

🤖 Generated with Claude Code

@read-the-docs-community

read-the-docs-community Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 Pyjo-Reactor-Winloop | 🛠️ Build #35673145 | 📁 Comparing 1751a93 against latest (7a11ca1)

  🔍 Preview build  

1 file changed
± index.html

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Tests

Job Tests Passed ✅ Skipped ⚠️ Failed ❌ Log
prove (python 3.12) 7091 7020 71 0 ✅ 127314916689
prove (python 3.13) 7080 7007 71 2 ❌ 127314916560
prove (python 3.14) 7122 7056 66 0 ✅ 127314916668
prove (python 3.15) 7122 7056 66 0 ✅ 127314916516
prove (python 3.15t) 7111 7043 66 2 ❌ 127314916587
All 35526 35182 340 4 ❌
Job Script Test Message
prove (python 3.13) t/Pyjo/Prove.py 15 - Capture the standard error
prove (python 3.13) t/Pyjo/Prove.py No plan found in TAP output
prove (python 3.15t) t/Pyjo/Prove.py 15 - Capture the standard error
prove (python 3.15t) t/Pyjo/Prove.py No plan found in TAP output

The run of the workflow

dex4er and others added 2 commits November 5, 2026 15:06
libuv of Windows polls a socket with an exclusive request of AFD, which
ends the request of any other loop for the same socket, also of a copy
of it, and that loop polls it again, in a busy loop of C with no event
at all. The workers of Pyjo.Server.Prethread watch the listen sockets of
the manager on Windows, the same sockets in every thread: four idle
loops took 240% of the processors and starved the process and the tests
next to it, with or without the GIL.

_Loop keeps the readers and the writers of each socket, and a registry
of the process has the loops that watch it, the owner that libuv polls
it for, and the loops that run and wait for it. The owner hands it over
to the next one after each of its events, so that the connections go to
every worker in turn, and at the end of its run; a loop changes the
polls of libuv only in its thread. A socket that one loop watches goes
to libuv as before.

Closes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pyjoyment of Git main with pyjoyment/Pyjoyment#550 and
pyjoyment/Pyjoyment#552, the tests of a page of GitHub without its title
in the tutorial and of the servers of Hot and Reload that did not answer
or did not stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dex4er and others added 2 commits November 5, 2026 15:25
Pyjoyment of Git main with pyjoyment/Pyjoyment#553, a sleep of
Pyjo.Steps in its tests on an event loop of libuv, whose timer may be
due a millisecond early, and pyjoyment/Pyjoyment#554, the data of a
connection that the daemon has removed discarded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libuv counts a timer in whole milliseconds from uv_now, its clock
rounded down, and Winloop rounds the delay to them, as uvloop does, so a
timer, as asyncio.sleep, was due up to a millisecond before its time,
where the loop of asyncio is never early: a sleep of 2 ms took 1.5 ms.
call_later of _Loop, which call_at of Winloop calls too, rounds the
delay up to a millisecond and adds the one that the clock loses, as
_Loop of Pyjo.Reactor.Uvloop does, after MagicStack/uvloop#755.

The subtest of Pyjo-Reactor-Uvloop measures with time.perf_counter,
which time.monotonic is on Windows since Python 3.13, and which counted
in the ticks of the system of 15.6 ms before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dex4er dex4er changed the title Pyjo.Reactor.Winloop: a socket that loops watch, polled by one at a time Pyjo.Reactor.Winloop: a socket that loops watch, polled by one at a time, and a timer not due before its time Nov 5, 2026
@dex4er
dex4er merged commit 09c7d51 into main Nov 5, 2026
9 of 12 checks passed
@dex4er
dex4er deleted the shared-sockets branch November 5, 2026 14:56
@dex4er dex4er added this to the 0.1.0 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loops of Winloop that watch one socket poll it in a busy loop, as the workers of Pyjo.Server.Prethread

1 participant