Repository navigation
Fix sem_clockwait detection - #985
Conversation
When cross-compiling against old glibc headers (e.g., Debian Stretch's glibc 2.24), configure cannot detect sem_clockwait (added in glibc 2.30). This causes CPython to fall back to sem_timedwait with CLOCK_REALTIME, making threading.Event.wait() hang indefinitely when the system clock jumps backward (e.g., NTP sync). Add patches that declare sem_clockwait as a weak symbol on Linux when configure didn't detect it. At runtime, the weak symbol resolves to the real function on glibc 2.30+ or to NULL on older glibc. The patched code checks this at runtime and falls back to sem_timedwait gracefully. Version-specific patches for CPython 3.10, 3.11, 3.12, and 3.13+ account for differences in the threading internals across versions.
|
Looks like the patch needs to be modified to apply cleanly on 3.15 (currently in alpha). |
a688da3 to
8ac6af1
Compare
In 3.15, the semaphore lock code moved from thread_pthread.h to parking_lot.c.
8ac6af1 to
4f545d7
Compare
|
Added the 3.15 patch. The 3.15 one is simpler than the others. |
|
Cross compiling is not really the issue here. The project build both natively and cross against an older glibc for compatibility. It would be good if the comments described this more clearly. Perhaps something like: |
… "cross-compiling"
|
You are right, cross compiling is not the issue here. Updated the patch comments and PR title/description. |
geofft
left a comment
There was a problem hiding this comment.
These changes look good to me, thanks very much for the PR! I'm slowly working on doing this kind of thing in general to all the newer symbols and I might end up reworking this one a bit in the process, but I think the argument about hanging (and the provided patch :) ) is a good one to do this one first.
|
We'll be doing a release this week anyway for CPython 3.15.0a7 so this should be available shortly. |
…260310 Update requires-python from >=3.12.3 to >=3.12.13 to match the CPython 3.12.13 release in python-build-standalone 20260310. This build contains the time patch needed to work on comma devices with older glibc. References: - astral-sh/python-build-standalone#985 - commaai#33993 (comment) https://claude.ai/code/session_01J4RLFmvFZibVpt1Tjgfxqv
…260310 Update requires-python from >=3.12.3 to >=3.12.13 to match the CPython 3.12.13 release in python-build-standalone 20260310. This build contains the time patch needed to work on comma devices with older glibc. References: - astral-sh/python-build-standalone#985 - commaai#33993 (comment)
…0310 Add .python-version pinning Python to 3.12.13 to match the CPython 3.12.13 release in python-build-standalone 20260310. The pyproject.toml floor stays at >=3.12.3. This build contains the time patch needed to work on comma devices with older glibc. References: - astral-sh/python-build-standalone#985 - commaai#33993 (comment)
When building against glibc headers older than 2.30 (e.g., Debian Stretch's
glibc 2.24), configure cannot detectsem_clockwait(added in glibc 2.30). This causes CPython to fall back tosem_timedwaitwith CLOCK_REALTIME, makingthreading.Event.wait()hang indefinitely when the system clock jumps backward (e.g., NTP sync).This PR adds patches that declare
sem_clockwaitas a weak symbol on Linux when configure doesn't detect it. At runtime, the weak symbol resolves to the real function onglibc 2.30+or to NULL on older glibc. The patched code checks this at runtime and falls back tosem_timedwaitgracefully.Version-specific patches for CPython 3.10, 3.11, 3.12, 3.13+ (including 3.14) and 3.15 (currently in alpha) account for differences in the threading internals across versions.
The issue was first discovered in commaai/openpilot#33993 (comment)
Test results
All patches verified by building on Debian Stretch (glibc 2.24, where
sem_clockwaitdoesn't exist in headers) and running on Debian Bookworm (glibc 2.36):Event.wait(0.1)sem_timedwaitfallbacktest-sem-clockwait.py