13

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?

3
  • 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? Commented Jun 11, 2011 at 21:18
  • Yes, its already running and I want to see whats going on without modifying the script. Commented 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. Commented Jun 11, 2011 at 21:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

None of the answers to that question support attaching to a script that wasn't already instrumented for debugging
@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.