Repository navigation
Fix pystemd.run waits and pystemd.futures on systemd 259 / Python 3.14 - #126
Merged
Merged
Conversation
aleivag
force-pushed
the
fix-futures-systemd259-py314
branch
7 times, most recently
from
October 30, 2026 00:01
2db3f13 to
c80ed8e
Compare
peturingi
approved these changes
Nov 1, 2026
peturingi
reviewed
Nov 2, 2026
peturingi
left a comment
There was a problem hiding this comment.
Good job.
All of my suggestions, except the one where ValueError is thrown for None while the type-hint specifies (thereby an interface contract) that None is valid, are mere personal preferences -- feel free to ignore them.
aleivag
force-pushed
the
fix-futures-systemd259-py314
branch
from
November 16, 2026 17:59
aff2d8c to
a6df5af
Compare
This was referenced Nov 16, 2026
pystemd.run:
- wait=True / wait_for_activation=True could block forever: systemd only
emits unit PropertiesChanged signals while some client has called
Manager.Subscribe(), and run() only eavesdrops via BecomeMonitor. On a
desktop something else is usually subscribed; on a minimal host
(e.g. a Fedora 44 cloud VM) nobody is. Subscribe before starting the unit.
- Drain every message sd-bus has buffered on each wakeup. One socket read
can bring several signals, and select() does not fire again for the ones
already read, so processing one message per wakeup could miss the state
change we are waiting for.
pystemd.futures:
- Python 3.14 made forkserver the default start method on Linux, which
broke TransientUnitPoolExecutor ("SemLock created in a fork context is
being shared with a process in a spawn context"). Workers now subclass
ForkProcess, which enter_unit relies on anyway.
- Start the anchor unit with Type=exec. With Type=simple the unit is
reported running right after fork, while systemd >= 255's executor is
still root, so enter_unit copied uid 0 and User= was ignored.
- The pool's anchor process is now `tail --pid=<parent>` instead of
`sleep infinity` (as TransientUnitProcess already does), so the unit
does not leak when the parent dies without reaching __exit__.
Tested on Fedora 44 (systemd 259, kernel 6.19, aarch64, Python 3.14):
futures.run with User=nobody + PrivateNetwork, CPUQuota and MemoryMax;
examples/future_cpucap_{method,process,pool}.py; unit tests pass.
wait_for_activation=True only stopped waiting when it saw SubState "running" for the start job. A Type=notify or Type=exec unit that fails during startup never gets there (it goes straight to "failed"), so pystemd.run() blocked forever. Also stop once the start job is over and the unit is in an exit substate (exited/failed/dead), the same condition wait=True uses; with raise_on_fail the caller then gets PystemdRunError as usual. Tested on systemd 259: Type=notify `sh -c "exit 3"` and Type=exec `/nonexistent` now return in ~20ms as failed/failed (both hung before); a Type=notify unit that sends READY=1 still waits for it.
aleivag
force-pushed
the
fix-futures-systemd259-py314
branch
from
November 18, 2026 18:56
a6df5af to
6d2ccbe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pystemd.run:
sh -c "exit 3"and Type=exec/nonexistentreturn in ~20ms as failed (both hung before); a Type=notify unit that sends READY=1 still waits for it.pystemd.futures:
tail --pid=<parent>instead ofsleep infinity(as TransientUnitProcess already does), so the unit does not leak when the parent dies without reaching exit.Tested on Fedora 44 (systemd 259, kernel 6.19, aarch64, Python 3.14): futures.run with User=nobody + PrivateNetwork, CPUQuota and MemoryMax; examples/future_cpucap_{method,process,pool}.py; unit tests pass.