IPython Notebook - Keep printing to notebook output after closing browser

后端 未结 1 710
既然无缘
既然无缘 2021-01-02 05:45

I\'m doing long-running experiments in an IPython notebook running on a server, where the typical work cycle is: launch experiment, go to lunch, come back, check progress, c

相关标签:
1条回答
  • 2021-01-02 06:10

    Well, found an ok solution. Solution is in this file: https://github.com/QUVA-Lab/artemis/blob/master/artemis/fileman/persistent_print.py

    With example use: https://github.com/QUVA-Lab/artemis/blob/master/artemis/fileman/test_persistent_print.py

    The demo now looks like:

    import time
    from general.persistent_print import capture_print, reprint
    capture_print()
    start_time = time.time()
    for i in xrange(5):
        print '%s seconds have passed' % (time.time()-start_time)
        time.sleep(2)
    print 'Done!'
    

    And if I run

    reprint()
    

    In the next cell, it will redisplay all the print statements made since capture_print was called. Obviously it would be better if this were unnecessary, but it works for now.

    0 讨论(0)
提交回复
热议问题