How can I tell where my python script is hanging?

后端 未结 13 782
醉话见心
醉话见心 2020-12-04 08:10

So I\'m debugging my python program and have encountered a bug that makes the program hang, as if in an infinite loop. Now, I had a problem with an infinite loop before, but

13条回答
  •  Happy的楠姐
    2020-12-04 08:29

    I wrote a module that prints out threads that hang longer that 10 seconds at one place. hanging_threads.py

    Run:

    python -m pip install hanging_threads
    

    Add this to your code:

    from hanging_threads import start_monitoring
    start_monitoring(seconds_frozen=10, test_interval=100)
    

    Here is an example output:

    --------------------    Thread 5588     --------------------
      File "C:\python33\lib\threading.py", line 844, in _exitfunc
            t.join()
      File "C:\python33\lib\threading.py", line 743, in join
            self._block.wait()
      File "C:\python33\lib\threading.py", line 184, in wait
            waiter.acquire()
    

    This occurs at the exit of the main thread when you forget to set another thread as daemon.

提交回复
热议问题