Is there a way to connect to the currently running python script to find out what is happening?

I have a python script that sometimes freezes and I would like to know why? Is there a way to connect to a python script and see which variables are what its string is and / or what it does?

+6
source share
2 answers

Original answer

Use a debugger as shown in answers to How to connect a remote debugger to a Python process?

After joining, you can pause execution and view variables, current stack, etc.

Update

As noted in the comments related to debuggers, it seems to require the process to start in a certain way. Visual Studio (with Python Tools installed) supports joining the current process.

+1
source

Add the following line:

import pdb; pdb.set_trace() 
-4
source

Source: https://habr.com/ru/post/890304/


All Articles