Skip to content

cProfile hangs / segfaults with 3.13t #125165

Description

@andrewkho

Bug report

Bug description:

I'm testing Python 3.13t and trying to run cProfile in a context manager, however it seems to hang and/or segfault.

Below script repros the issue.

With > python -Xgil=1 test_cProfile.py profile
it succeeds as expected, however disabling -Xgil=0 causes it to usually hang.

""" example script showing deadlock with python 3.13t and cProfile context managerpython -Xgil=0 test_cProfile.py # runs normallypython -Xgil=0 test_cProfile.py profile # hangs"""importcProfileimportsysimporttimeimportthreadingimportqueuedefworker(wid, q, stop):
whilenotstop.is_set():
try:
x=q.get(timeout=1.)
print(wid, x)
exceptqueue.Empty:
continuedefrun():
stop=threading.Event()
workers= []
queues= []
num_workers=2forwidinrange(num_workers):
queues.append(queue.Queue())
workers.append(threading.Thread(target=worker, args=(wid, queues[-1], stop)))
workers[-1].start()
foriinrange(100):
queues[i%num_workers].put(i)
whileany(q.qsize() forqinqueues):
print("Waiting...")
time.sleep(0.1)
continueprint("stop.set()")
stop.set()
forwidinrange(num_workers):
print("Joining", wid)
workers[wid].join()
print("Done")
defmain():
iflen(sys.argv) >1andsys.argv[1] =="profile":
print("Profiling with cProfile")
withcProfile.Profile() aspr:
run()
else:
print("Running without cProfile")
run()
if__name__=="__main__":
main()
commentedonthispaste.```
### CPython versions tested on:3.13### Operating systems tested on:Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions