Is There Any Way To Retrieve A Local Variable From A Running Function?
Desperate. Say we have the following: def main(): ALotOFCode list1 = [] list2 = [] while condition: # a lot of times where raw_input is used in this loop # e.g. x = raw_
Solution 1:
To be able to "read" internal variables for debug purpose I see following ideas:
create a log file with a line for each variable change and before each blocking function. Even if the log is huge. And then follow log with "tail" on Raspberry (new console or new remote connection).
Transform variables to be global and add some code which ouputs all variables to standard output when a special key is hit, for example Ctrl+C which interrupts almost everything. If transforming variables to global isn't possible (due to nested calls reasons for example), create new variables which holds last known values.
Ctrl+C handling could be done like that (from here) :
#!/usr/bin/env pythonimport signal
import sys
defsignal_handler(signal, frame):
print('You pressed Ctrl+C!')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
print('Press Ctrl+C')
signal.pause()
As you see, my options implies to modifiy the code to make it chatty or queryable.
Post a Comment for "Is There Any Way To Retrieve A Local Variable From A Running Function?"