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?
Asked
Active
Viewed 4,347 times
13
-
You mean the script is already running, and you somehow want to attach a Python debugger to the running script, without modifying the script in any way? – Sven Marnach Jun 11 '11 at 21:18
-
Yes, its already running and I want to see whats going on without modifying the script. – Incognito Jun 11 '11 at 21:20
-
If the script is already running, I think you are out of luck. All options I'm aware of either require a line of code to be injected into our script or to start the script using some debugging server. – Sven Marnach Jun 11 '11 at 21:33
-
2possible duplicate of [How do I attach a remote debugger to a Python process?](http://stackoverflow.com/questions/543196/how-do-i-attach-a-remote-debugger-to-a-python-process) – Piotr Dobrogost Jul 22 '15 at 18:10
1 Answers
1
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.
-
2None of the answers to that question support attaching to a script that wasn't already instrumented for debugging – Michael Mrozek Jun 15 '16 at 19:08
-
@MichaelMrozek Thanks, I hadn't spotted that. I know it's something Visual Studio is capable of doing, I simply assumed others would be equally capable. Example of how to do it in VS: https://github.com/Microsoft/PTVS/wiki/Debugging (Assuming you have Python Tools for VS installed) `Visual Studio includes support for debugging applications including attaching to running processes, evaluating expressions in the watch and immediate windows, and inspecting local variables, step in, out, and over statements, set the next statement, and breaking on exceptions.` – Basic Jun 15 '16 at 19:16