##// END OF EJS Templates
More work on long-lived Trio loop...
More work on long-lived Trio loop -Better handling for race condition on loop startup -Better handling of errors for tasks in the global nursery: it doesn't crash the global nursery, it just logs the exception -And some other code cleanup Co-authored-by: Brian Mackintosh <bcmackintosh@gmail.com>

File last commit:

r24897:5df756a9
r25426:018538a0
Show More
ipython-get-history.py
39 lines | 1.1 KiB | text/x-python | PythonLexer
#!/usr/bin/env python
"""Extract a session from the IPython input history.
Usage:
ipython-get-history.py sessionnumber [outputfile]
If outputfile is not given, the relevant history is written to stdout. If
outputfile has a .py extension, the translated history (without IPython's
special syntax) will be extracted.
Example:
./ipython-get-history.py 57 record.ipy
This script is a simple demonstration of HistoryAccessor. It should be possible
to build much more flexible and powerful tools to browse and pull from the
history database.
"""
import sys
from IPython.core.history import HistoryAccessor
session_number = int(sys.argv[1])
if len(sys.argv) > 2:
dest = open(sys.argv[2], "w")
raw = not sys.argv[2].endswith('.py')
else:
dest = sys.stdout
raw = True
with dest:
dest.write("# coding: utf-8\n")
# Profiles other than 'default' can be specified here with a profile= argument:
hist = HistoryAccessor()
for session, lineno, cell in hist.get_range(session=session_number, raw=raw):
cell = cell.encode('utf-8') # This line is only needed on Python 2.
dest.write(cell + '\n')