Get stacktrace from stuck python process

后端 未结 5 1213
北荒
北荒 2021-01-03 01:15

I have to run a legacy Zope2 website and have some grievance with it. The biggest issue is that, occasionally, it just locks up, running at 100% CPU load and not answering t

5条回答
  •  有刺的猬
    2021-01-03 01:48

    You can print out a nice stack trace using pyrasite.

    First, you'll need to have gdb installed.

    # Redhat, CentOS, etc
    $ yum install gdb
    
    # Ubuntu, Debian, etc
    $ apt-get update && apt-get install gdb
    

    Then, install pyrasite.

    $ pip install pyrasite
    

    Use ps or some other method to find the process ID for the stuck python process and run pyrasite-shell with it.

    # Assuming process ID is 12345
    $ pyrasite-shell 12345
    

    You should now see a python REPL. Run the following in the REPL to see stack traces for all threads.

    import sys, traceback
    for thread_id, frame in sys._current_frames().items():
        print 'Stack for thread {}'.format(thread_id)
        traceback.print_stack(frame)
        print ''
    

提交回复
热议问题