Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the current line number of a running python process

I have long-running python programs that do not have sufficient internal logging. I'd like to be able to attach to a running python program and find out it's current line number. Ideally, I'd like to do this without interrupting its execution, but I'm happy to have it pause, print the stack t race, and then keep going.

I could easily type control-C, but that would kill the program.

Is there any way to do this?

like image 715
vy32 Avatar asked Jan 03 '19 15:01

vy32


People also ask

Can you run Python code line by line?

One thing that distinguishes Python from other programming languages is that it is interpreted rather than compiled. This means that it is executed line by line, which allows programming to be interactive in a way that is not directly possible with compiled languages like Fortran, C, or Java.


1 Answers

Seems like py-spy is what you are looking for.

It can connect to running process without modifying and show what it currently do.

like image 176
Danyla Hulchuk Avatar answered Sep 20 '22 13:09

Danyla Hulchuk