1

If one of our linux system is overloaded, then I would like to take a snapshot of what is going on.

99% of our code is Python, that's why I would like to get a stacktrace of all running python interpreters.

I have no clue how to get the stacktrace of python processes.

This question is only about how to get the stacktrace. The condition which checks if I want it to happen is a different question (which is already solved).

I know that it is possible to get the stacktrace by using a signal handler (See here), but I would like to avoid this. The python source code should not get modified to solve this.

7
  • Just curious - how would stack traces help you determine the cause of system overload?
    – Mawg
    Commented Jul 30, 2018 at 9:42
  • 1
    @Mawg you want to know why stacktraces help me? Because I can see what is going on. If I just know "some python processes are running at 100% CPU" I do not know much. But if I can see the stacktraces, then I can see what the python processes are actually doing.
    – guettli
    Commented Jul 30, 2018 at 12:38
  • Thanks (+1) I was wondering how, without looking in detail at lots of stack dumps, you would know which one was causing the 100% CPU. Can't you give them all unique process name, then run top or look at the Windows taskmgr, to see which process is hogging CPU? And can't you limit their CPU somehow? In short, I am wondering of this is really the best question for you to ask :-)
    – Mawg
    Commented Jul 30, 2018 at 13:09
  • @Mawg if this is not the best question, which one would be better?
    – guettli
    Commented Jul 30, 2018 at 13:11
  • To me, it sounds like a "which process is eating my CPU" question? Wouldn't top help? Can't you give them all unique process names, have another process which is a watchdog and when CPU > 90% it snapshots the offender? Or, can't you use the O/S's parameters to create process/thread, to limit CPU usage, as you can stack size? Maybe adjust priority? You might get better help on unix.stackexchange.com
    – Mawg
    Commented Jul 30, 2018 at 13:39

3 Answers 3

1

The tool pyrasite:

Tools for injecting arbitrary code into running Python processes.

This way you can get a stacktrace of running python processes.

No need to modify the python source and no need to work with signal handlers :-)

0

The tool python-hunter could be used to extract the stacktraces

Hunter is a flexible code tracing toolkit, not for measuring coverage, but for debugging, logging, inspection and other nefarious purposes. It has a Python API, terminal activation (see Environment variable activation). and supports tracing other processes

0

The too pyflame can be used to dump stacktraces of running interpreters:

Is There A Way To Just Dump Stack Traces?

Yes, use the -d option.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.