3

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_input('lots of steps to compute x')
  y = raw_input('lots of steps to compute y')  
  list1 = list1.append(x)
  list2 = list2.append(y)
  stream.write({'x':list1,'y':list2}) #send new data point to plot.ly via raspberry pi

I don't know what happened. But my plot in plot.ly is gone. Deleted completely. I was messing with what I had on the plot thus far on my PC and then I continued inputting data and building the plot from raspberry pi. I could see the plot being built no problem. Then I went back to my PC and hit refresh. Plot and all data gone. Went back to raspberry. Already synced. Gone.

I know though that list1 and list2 right now as I am writing this contain all the data I need to remake my plot. But is there any way at all to access it and save it to file? My python shell is currently waiting for input via raw_input so I cant use the shell. Is there any way I can terminal my way into the variables currently in the scope of the still running program? Obviously once the program ends the local variables are deleted.

Of course if a history is saved for each plot on plot.ly that would help to but I cant find any restore to previous state option.

Update: So - thank god - I had saved the outputs of some of my intermediate steps to file. I effectively gave up trying to access the variable and instead tried generating list1 and list2 through a new on-the-fly script. At 8:30am in the morning I had my data and at 10am my supervisor happily looked at it none the wiser. This question remains open though as yet nobody has given a clear answer or explained how accessing list1 and list2 directly isn't possible. (I did go through each suggestion in the comments but couldn't find anything that provided an answer)

Obligatory final comment: My faith in Plot.ly has been shattered, at least for a while.

Frikster
  • 2,755
  • 5
  • 37
  • 71
  • 1
    I seriously doubt it's possible to do what yo are asking in any kind of sane or safe way. If I'm understanding you correctly. – kylieCatt Aug 07 '15 at 12:51
  • See [attaching a process with pdb](http://stackoverflow.com/questions/25308847/attaching-a-process-with-pdb). Doesn't look good I'm afraid. – Peter Wood Aug 07 '15 at 12:55
  • maybe you can use tcpdump to capture the output when stream is written (if it is a network stream). – gauteh Aug 07 '15 at 13:14

1 Answers1

0

To be able to "read" internal variables for debug purpose I see following ideas:

  1. 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).

  2. 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 python
import signal
import sys
def signal_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.

Community
  • 1
  • 1
Elo
  • 2,234
  • 22
  • 28