1

To introduce my question let get an example.

I have a file code.py. Let's say I run it, python code.py which takes some time. Python starts a process, call it p0.

Obviously changing code.py during p0 won't change its execution, because the code, code.py is loaded at the begining.

My point is then: is there a way, knowing p0's pid to see/print the python code currently used by p0 i.e. code.py's "version" when p0 started?

I'm quite curious about how difficult this could be, and, as python isn't a compiled language, I think there may be the original python source, somewhere. Plus, it's quite hacky, but this could help me when I'm not 100% sure how was the code when I started a looooong process (then modified the file, yes that's not a really good pratice, must say).

Any clue? thx folks

pltrdy

pltrdy
  • 2,069
  • 1
  • 11
  • 29
  • attach debugger gdb to the pid – vks Dec 21 '16 at 09:33
  • Is it a thread or a system execution call you're referring to as `p0`? – Torxed Dec 21 '16 at 09:37
  • @vks i'll look @ gdb for python. I know that we can get trace + infos about variables. Not sure about printing the code itself, but this can help anyway. @Torxed: `p0` is the process started by `python` command. Is it clear? – pltrdy Dec 21 '16 at 09:47
  • once gdb is attached you can actually see what part of code is executing at moment........also if it has threads u can see which thread etc – vks Dec 21 '16 at 09:48
  • As you can change the original code itself, you can use the method on http://stackoverflow.com/a/25329467/2591803 to add the ability to send signals to get a pdb debugger session. This won't work with currently running processes but should be easier than using gdb for the future. – Chris Midgley Dec 21 '16 at 09:51

0 Answers0