Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed as not planned
Description
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