Is it possible to find any information about what a Python program running right now is doing without interrupting it?
Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?
I know I should have used logs or run it in debug mode or inserted a statement to run the debugger...
Related questions
To check if process is running or not, let's iterate over all the running process using psutil. process_iter() and match the process name i.e. import psutil def checkIfProcessRunning(processName): ''' Check if there is any running process that contains the given name processName.
time() : Measure the the total time elapsed to execute the code in seconds. timeit. timeit() : Simple way to time a small piece of Python code. %timeit and %%timeit : command to get the execution time of a single line of code and multiple lines of code.
Inspect running process with pyrasite Find the process ID for the stuck Python process and run pyrasite-shell with it. You should now see a Python REPL. Run the following in the REPL to see stack traces for all threads.
If you place
import code
code.interact(local=locals())
at any point in your script, python will instantiate a python shell at exactly that point that has access to everything in the state of the script at that point. ^D exits the shell and resumes execution past that point.
You can even modify the state at that point from the shell, call functions, etc.
If you have a running Python, which wasn't built with any sort of trace or logging mechanism, and you want to see what it's doing internally, then two options are:
On a Solaris or Mac, if you are using the system-provided Python then use dtrace
use gdb to attach to a running Python process,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With