pytorch - 💡(How to fix) Fix DISABLED test_unexpected_c_return_events (__main__.TestPythonTracer) [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#176996Fetched 2026-04-08 00:23:13
View on GitHub
Comments
1
Participants
1
Timeline
60
Reactions
0
Participants
Timeline (top)
mentioned ×28subscribed ×28labeled ×3commented ×1

Error Message

Traceback (most recent call last): File "/var/lib/jenkins/workspace/test/profiler/test_python_tracer.py", line 99, in test_unexpected_c_return_events result = subprocess.run( [sys.executable, "-c", code], capture_output=True, text=True, check=True ) File "/opt/conda/envs/py_3.14/lib/python3.14t/subprocess.py", line 577, in run raise CalledProcessError(retcode, process.args, output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['/opt/conda/envs/py_3.14/bin/python', '-c', '\nimport threading\nimport time\nimport torch\n\nfrom threading import Event, Lock\n\nlock = Lock()\nlock.acquire()\nevent1 = Event()\nevent2 = Event()\nevent3 = Event()\n\ndef run():\n event1.set()\n event2.wait()\n lock.acquire()\n event3.set()\n\nthreading.Thread(target=run).start()\n\nwith torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):\n event1.wait()\n event2.set()\n time.sleep(1)\n\nwith torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):\n lock.release()\n event3.wait()\n ']' returned non-zero exit status 1.

Root Cause

This test was disabled because it is failing in CI. See recent examples and the most recent trunk workflow logs.

Code Example

Traceback (most recent call last):
  File "/var/lib/jenkins/workspace/test/profiler/test_python_tracer.py", line 99, in test_unexpected_c_return_events
    result = subprocess.run(
        [sys.executable, "-c", code], capture_output=True, text=True, check=True
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/subprocess.py", line 577, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/opt/conda/envs/py_3.14/bin/python', '-c', '\nimport threading\nimport time\nimport torch\n\nfrom threading import Event, Lock\n\nlock = Lock()\nlock.acquire()\nevent1 = Event()\nevent2 = Event()\nevent3 = Event()\n\ndef run():\n    event1.set()\n    event2.wait()\n    lock.acquire()\n    event3.set()\n\nthreading.Thread(target=run).start()\n\nwith torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):\n    event1.wait()\n    event2.set()\n    time.sleep(1)\n\nwith torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):\n    lock.release()\n    event3.wait()\n    ']' returned non-zero exit status 1.
RAW_BUFFERClick to expand / collapse

Platforms: linux

This test was disabled because it is failing in CI. See recent examples and the most recent trunk workflow logs.

Over the past 6 hours, it has been determined flaky in 4 workflow(s) with 4 failures and 4 successes.

Debugging instructions (after clicking on the recent samples link): DO NOT ASSUME THINGS ARE OKAY IF THE CI IS GREEN. We now shield flaky tests from developers so CI will thus be green but it will be harder to parse the logs. To find relevant log snippets:

  1. Click on the workflow logs linked above
  2. Click on the Test step of the job so that it is expanded. Otherwise, the grepping will not work.
  3. Grep for test_unexpected_c_return_events
  4. There should be several instances run (as flaky tests are rerun in CI) from which you can study the logs.
<details><summary>Sample error message</summary>
Traceback (most recent call last):
  File "/var/lib/jenkins/workspace/test/profiler/test_python_tracer.py", line 99, in test_unexpected_c_return_events
    result = subprocess.run(
        [sys.executable, "-c", code], capture_output=True, text=True, check=True
    )
  File "/opt/conda/envs/py_3.14/lib/python3.14t/subprocess.py", line 577, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/opt/conda/envs/py_3.14/bin/python', '-c', '\nimport threading\nimport time\nimport torch\n\nfrom threading import Event, Lock\n\nlock = Lock()\nlock.acquire()\nevent1 = Event()\nevent2 = Event()\nevent3 = Event()\n\ndef run():\n    event1.set()\n    event2.wait()\n    lock.acquire()\n    event3.set()\n\nthreading.Thread(target=run).start()\n\nwith torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):\n    event1.wait()\n    event2.set()\n    time.sleep(1)\n\nwith torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):\n    lock.release()\n    event3.wait()\n    ']' returned non-zero exit status 1.
</details>

Test file path: profiler/test_python_tracer.py

For all disabled tests (by GitHub issue), see https://hud.pytorch.org/disabled.

cc @robieta @chaekit @guotuofeng @guyang3532 @dzhulgakov @davidberard98 @briancoutinho @sraikund16 @sanrise @mwootton @divyanshk @jiannanWang @scotts @ryanzhang22

extent analysis

Fix Plan

1. Identify the Root Cause

The root cause of the issue is a flaky test due to a race condition in the test_unexpected_c_return_events test.

2. Fix the Test

To fix the test, we need to ensure that the events are properly synchronized. We can use a Condition object from the threading module to achieve this.

import threading
import time
import torch

lock = threading.Lock()
cond = threading.Condition(lock)

def run():
    event1.set()
    with cond:
        event2.wait()
        lock.acquire()
        event3.set()

threading.Thread(target=run).start()

with torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):
    event1.wait()
    event2.set()
    time.sleep(1)

with torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU], with_stack=True):
    with cond:
        lock.release()
        event3.wait()

3. Verify the Fix

To verify the fix, we can re-run the test and check if it passes consistently.

4. Update the Test File

Update the profiler/test_python_tracer.py file with the fixed test code.

# profiler/test_python_tracer.py
import threading
import time
import torch

# ... (rest of the test code remains the same)

def test_unexpected_c_return_events():
    # ... (rest of the test code remains the same)

5. Re-run the Test

Re-run the test and verify that it passes consistently.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix DISABLED test_unexpected_c_return_events (__main__.TestPythonTracer) [1 comments, 1 participants]