Fix hanging coverage workflow#3004
Merged
Merged
Conversation
Force Cython's legacy (settrace-based) line tracing instead of the sys.monitoring path enabled by default on Python 3.13+. The sys.monitoring trace hooks emitted into the compiled extension fire exception/unwind events without preserving the in-flight exception, corrupting the interpreter error state when an exception propagates out of an instrumented .pyx frame (e.g. usm_ndarray.__dlpack__), turning it into a SystemError and hanging the coverage run. See cython/cython#6658.
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
Contributor
|
Array API standard conformance tests for dpnp=0.21.0dev3=py314h509198e_9 ran successfully. |
antonwolfy
marked this pull request as ready for review
July 21, 2026 14:31
antonwolfy
requested review from
ndgrigorian and
vlad-perevezentsev
as code owners
July 21, 2026 14:31
Collaborator
vlad-perevezentsev
approved these changes
Jul 21, 2026
vlad-perevezentsev
left a comment
Contributor
There was a problem hiding this comment.
LGTM
Thank you @antonwolfy
github-actions Bot
added a commit
that referenced
this pull request
Jul 22, 2026
The GutHub coverage workflow started hanging right after the coverage environment was bumped from Python 3.12 to 3.14 (#2922). This PR fixes the hang by compiling the coverage build with `CYTHON_USE_SYS_MONITORING=0`, forcing Cython to use its legacy `settrace`-based line tracing instead of the `sys.monitoring` path that becomes the default on Python 3.13+. ### Root cause Coverage builds compile every Cython extension with line tracing (`CYTHON_TRACE=1 CYTHON_TRACE_NOGIL=1` + `# cython: linetrace=True`). On Python 3.13+, Cython gates its tracing implementation on `CYTHON_USE_SYS_MONITORING` (`PY_VERSION_HEX >= 0x030d00B1`) and emits `sys.monitoring` hooks directly into the compiled `.so`. Those hooks fire exception/unwind events (`PyMonitoring_FireRaiseEvent`, `PyMonitoring_FirePyUnwindEvent`, ...) **without preserving the in-flight exception** — unlike the legacy path (`__Pyx_call_line_trace_func`), which brackets the trace call with `PyErr_Fetch`/`PyErr_Restore`. When an exception propagates out of an instrumented `.pyx` frame, this corrupts the interpreter's error state: the correct exception is turned into a `SystemError` ("returned a result with an exception set"), and the process then hangs. This is an upstream Cython bug: cython/cython#6658 (open, same failure mode — Cython + coverage + Python 3.13 `sys.monitoring` → `SystemError` and hang). The first test to trigger this is `test_dlpack.py::TestDLPack::test_invaid_stream`, which does `assert_raises(TypeError, x.__dlpack__, stream=<invalid>)`. The `TypeError` is raised in the instrumented `dpnp/tensor/_usmarray.pyx` (`_validate_and_use_stream`) and unwinds out through `usm_ndarray.__dlpack__`, hitting the corruption. #### Why not just rely on `core = "ctrace"`? PR #2922 added `core = "ctrace"` in `pyproject.toml` to keep **coverage.py** off the `sysmon` measurement core (needed for the `Cython.Coverage` plugin). That is still required and unchanged. But it only controls coverage.py's own tracer — the corruption here comes from **Cython's compiled-in** `sys.monitoring` instrumentation, which is gated purely on the Python version and independent of coverage.py's core choice. `CYTHON_USE_SYS_MONITORING=0` addresses that side; the two settings are complementary. 987f299
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.
The GutHub coverage workflow started hanging right after the coverage environment was bumped from Python 3.12 to 3.14 (#2922).
This PR fixes the hang by compiling the coverage build with
CYTHON_USE_SYS_MONITORING=0, forcing Cython to use its legacysettrace-based line tracing instead of thesys.monitoringpath that becomes the default on Python 3.13+.Root cause
Coverage builds compile every Cython extension with line tracing (
CYTHON_TRACE=1 CYTHON_TRACE_NOGIL=1+# cython: linetrace=True). On Python 3.13+, Cython gates its tracing implementation onCYTHON_USE_SYS_MONITORING(PY_VERSION_HEX >= 0x030d00B1) and emitssys.monitoringhooks directly into the compiled.so.Those hooks fire exception/unwind events (
PyMonitoring_FireRaiseEvent,PyMonitoring_FirePyUnwindEvent, ...) without preserving the in-flight exception — unlike the legacy path (__Pyx_call_line_trace_func), which brackets the trace call withPyErr_Fetch/PyErr_Restore. When an exception propagates out of an instrumented.pyxframe, this corrupts the interpreter's error state: the correct exception is turned into aSystemError("returned a result with an exception set"), and the processthen hangs.
This is an upstream Cython bug: cython/cython#6658 (open, same failure mode — Cython + coverage + Python 3.13
sys.monitoring→SystemErrorand hang).The first test to trigger this is
test_dlpack.py::TestDLPack::test_invaid_stream, which doesassert_raises(TypeError, x.__dlpack__, stream=<invalid>). TheTypeErroris raised in the instrumenteddpnp/tensor/_usmarray.pyx(_validate_and_use_stream) and unwinds out throughusm_ndarray.__dlpack__, hitting the corruption.Why not just rely on
core = "ctrace"?PR #2922 added
core = "ctrace"inpyproject.tomlto keep coverage.py off thesysmonmeasurement core (needed for theCython.Coverageplugin). That is still required and unchanged. But it only controls coverage.py's own tracer — the corruption here comes from Cython's compiled-insys.monitoringinstrumentation, which is gated purely on the Python version and independent of coverage.py's core choice.CYTHON_USE_SYS_MONITORING=0addresses that side; the two settings are complementary.