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?
-
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– Sven Marnach2011-06-11 21:18:03 +00:00Commented Jun 11, 2011 at 21:18
-
Yes, its already running and I want to see whats going on without modifying the script.Incognito– Incognito2011-06-11 21:20:26 +00:00Commented Jun 11, 2011 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– Sven Marnach2011-06-11 21:33:06 +00:00Commented Jun 11, 2011 at 21:33
Add a comment
|
1 Answer
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.
2 Comments
Michael Mrozek
None of the answers to that question support attaching to a script that wasn't already instrumented for debugging
Basic
@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: 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.