Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way of hooking into a currently running python script to see whats going on?

I have a python script that occasionally freezes and I'd like to find out why? Is there a way to hook into a python script and see what the variables are what line its on and/or what its doing?

like image 799
Incognito Avatar asked Jun 11 '11 21:06

Incognito


People also ask

Can you change a Python script while it's running?

Imagine a python script that will take a long time to run, what will happen if I modify it while it's running? Will the result be different? The program is loaded into your main memory. If you change the source file, nothing happens.

Which tools allow you to interpret and run a Python program?

Running Python Scripts using an IDE or a Text Editor You can use other IDEs like Spyder, PyCharm, Eclipse, and Jupyter Notebook which also allow you to run your scripts inside its environment. You can also use popular text editors like Sublime and Atom to run Python script.


1 Answers

Original Answer

Use a debugger as shown in the answers to How do I attach a remote debugger to a Python process?

Once attached, you can pause execution and examine variables, the current stack, etc...

Update

As pointed out in the comments, the linked debuggers apparently require the process to be launched in a particular manner. Visual Studio (With Python Tools installed) does support attaching to a running process.

like image 200
Basic Avatar answered Oct 15 '22 04:10

Basic