5

I've been using iPython (0.13.2) more frequently lately, and the logging seems like a great feature -- if I could get it to work right.

Currently, I'm able to start and specify a log file either through ipython --logfile ~/path/fake.log, or even in the middle of an iPython session with the %magic command %logstart ~/path/fake.log.

However, I can't seem to resume the session from the logfile, which seems to defeat the purpose in part. I've scoured Google and SO, but none of the recommended solutions here at SO or in the docs seem to work quite right.

I have tried:

  • from Bash
    • ipython -log ~/path/fake.log (source, result: [TerminalIPythonApp] Unrecognized flag: '-log')
    • ipython -logplay ~/path/fake.log (source and numerous others, result: [TerminalIPythonApp] Unrecognized flag: '-logplay')
    • ipython --logfile=~/path/fake.log (source, result: new log started, variables from previous session undefined)
  • from iPython
    • %logstart ~/path/fake.log append (source, result: old log continued but not loaded, variables from previous session undefined)

Two that are partially working (in that they try to import the logfile) but don't seem to be intended for this purpose are:

  • from bash: ipython -i ~/path/fake.log (source, result: if there were no errors in the session imports and works. If there were any errors, not imported and variables still unavailable. Logging not resumed.).
  • from ipython: %run ~/path/fake.log (no source, just guessed and tried. Result: same as above. Runs the file if there were no errors and variables are GTG. If there were errors, does not work. Does not resume logging.)

Is there any way in iPython 0.13.2 to resume a session that effectively "starts where you left off"? Thanks for any help you can provide.

Community
  • 1
  • 1
n8henrie
  • 2,737
  • 3
  • 29
  • 45

1 Answers1

4

All these save/restore sessions work by saving the interactions as py files and then trying to run the py file during restore. If an error like undefined variable happens, that prompts a python error and restore halts there, but it does restore values stored upto the error condition.

To avoid storing error conditions, use the suggestion at chosen answer of How to save a Python interactive session? :

save  my_session_name   1-4 6  9

Where my session will get the commands in In[1] through In[4] and skip In[5], save In[6], skip In[7], In[8] and save In[9]. This way you avoid offending interactions.

Restore the session later:

%run my_session_name.py
Community
  • 1
  • 1
nom-mon-ir
  • 3,748
  • 8
  • 26
  • 42
  • 1
    *but it does restore values stored upto the error condition.* -- this is not my experience, as I describe above. I have just re-tested to confirm. If I %logstart and do (on separate lines obviously) `this = 'is a test'` `that = 'produces an error"`, then %run the log, `this` remains undefined. – n8henrie Jul 24 '13 at 23:36
  • Hey, have you found a way to solve this later? I have this problem too now @n8henrie – Tony Chen Sep 23 '17 at 08:41