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?

Incognito
  • 1,883
  • 5
  • 21
  • 28
  • 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
  • 2
    possible 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 Answers1

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.

Community
  • 1
  • 1
Basic
  • 26,321
  • 24
  • 115
  • 201
  • 2
    None 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