I have a script that runs for days, and inside it there's a counter. The counter gets written to a file periodically, is it possible to find out the value that the counter is set from either another python script, linux command, or even java?
Example of simple python counter:
import time
import random
a = 0
while True:
a +=1
time.sleep(random.random())
I'm interested in the value of a
at a given time.
Yes, you could use any IPC method e.g., you could send the counter over a socket:
If you want to get the value from an already running process that you can't modify then you could try to attach a debugger:
To enable python-specific helper commands, add to your
~/.gdbinit
:The example gdb session could look like:
From another Python script, you could run gdb in the batch mode: