本文整理汇总了Python中IPython.InteractiveShell类的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShell类的具体用法?Python InteractiveShell怎么用?Python InteractiveShell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InteractiveShell类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, exec_lines=None):
self.cout = StringIO()
if exec_lines is None:
exec_lines = []
# Create config object for IPython
config = Config()
config.HistoryManager.hist_file = ":memory:"
config.InteractiveShell.autocall = False
config.InteractiveShell.autoindent = False
config.InteractiveShell.colors = "NoColor"
# create a profile so instance history isn't saved
tmp_profile_dir = tempfile.mkdtemp(prefix="profile_")
profname = "auto_profile_sphinx_build"
pdir = os.path.join(tmp_profile_dir, profname)
profile = ProfileDir.create_profile_dir(pdir)
# Create and initialize global ipython, but don't start its mainloop.
# This will persist across different EmbededSphinxShell instances.
IP = InteractiveShell.instance(config=config, profile_dir=profile)
atexit.register(self.cleanup)
sys.stdout = self.cout
sys.stderr = self.cout
# For debugging, so we can see normal output, use this:
# from IPython.utils.io import Tee
# sys.stdout = Tee(self.cout, channel='stdout') # dbg
# sys.stderr = Tee(self.cout, channel='stderr') # dbg
# Store a few parts of IPython we'll need.
self.IP = IP
self.user_ns = self.IP.user_ns
self.user_global_ns = self.IP.user_global_ns
self.input = ""
self.output = ""
self.tmp_profile_dir = tmp_profile_dir
self.is_verbatim = False
self.is_doctest = False
self.is_suppress = False
# Optionally, provide more detailed information to shell.
# this is assigned by the SetUp method of IPythonDirective
# to point at itself.
#
# So, you can access handy things at self.directive.state
self.directive = None
# on the first call to the savefig decorator, we'll import
# pyplot as plt so we can make a call to the plt.gcf().savefig
self._pyplot_imported = False
# Prepopulate the namespace.
for line in exec_lines:
self.process_input_line(line, store_history=False)
示例2: __init__
def __init__(self, exec_lines=None,state=None):
self.cout = DecodingStringIO(u'')
if exec_lines is None:
exec_lines = []
self.state = state
# Create config object for IPython
config = Config()
config.InteractiveShell.autocall = False
config.InteractiveShell.autoindent = False
config.InteractiveShell.colors = 'NoColor'
# create a profile so instance history isn't saved
tmp_profile_dir = tempfile.mkdtemp(prefix='profile_')
profname = 'auto_profile_sphinx_build'
pdir = os.path.join(tmp_profile_dir,profname)
profile = ProfileDir.create_profile_dir(pdir)
# Create and initialize global ipython, but don't start its mainloop.
# This will persist across different EmbededSphinxShell instances.
IP = InteractiveShell.instance(config=config, profile_dir=profile)
# io.stdout redirect must be done after instantiating InteractiveShell
io.stdout = self.cout
io.stderr = self.cout
# For debugging, so we can see normal output, use this:
#from IPython.utils.io import Tee
#io.stdout = Tee(self.cout, channel='stdout') # dbg
#io.stderr = Tee(self.cout, channel='stderr') # dbg
# Store a few parts of IPython we'll need.
self.IP = IP
self.user_ns = self.IP.user_ns
self.user_global_ns = self.IP.user_global_ns
self.input = ''
self.output = ''
self.is_verbatim = False
self.is_doctest = False
self.is_suppress = False
# Optionally, provide more detailed information to shell.
self.directive = None
# on the first call to the savefig decorator, we'll import
# pyplot as plt so we can make a call to the plt.gcf().savefig
self._pyplot_imported = False
# Prepopulate the namespace.
for line in exec_lines:
self.process_input_line(line, store_history=False)
示例3: __init__
def __init__(self):
self.cout = cStringIO.StringIO()
# Create config object for IPython
config = Config()
config.Global.display_banner = False
config.Global.exec_lines = ['import numpy as np',
'from pylab import *'
]
config.InteractiveShell.autocall = False
config.InteractiveShell.autoindent = False
config.InteractiveShell.colors = 'NoColor'
config.InteractiveShell.cache_size = 0
# create a profile so instance history isn't saved
tmp_profile_dir = tempfile.mkdtemp(prefix='profile_')
profname = 'auto_profile_sphinx_build'
pdir = os.path.join(tmp_profile_dir, profname)
profile = ProfileDir.create_profile_dir(pdir)
# Create and initialize ipython, but don't start its mainloop
IP = InteractiveShell.instance(config=config, profile_dir=profile)
# io.stdout redirect must be done *after* instantiating
# InteractiveShell
io.stdout = self.cout
io.stderr = self.cout
# For debugging, so we can see normal output, use this:
# from IPython.utils.io import Tee
# io.stdout = Tee(self.cout, channel='stdout') # dbg
# io.stderr = Tee(self.cout, channel='stderr') # dbg
# Store a few parts of IPython we'll need.
self.IP = IP
self.user_ns = self.IP.user_ns
self.user_global_ns = self.IP.user_global_ns
self.input = ''
self.output = ''
self.is_verbatim = False
self.is_doctest = False
self.is_suppress = False
# on the first call to the savefig decorator, we'll import
# pyplot as plt so we can make a call to the plt.gcf().savefig
self._pyplot_imported = False
示例4: __install
def __install():
log = logging.getLogger('tpython')
log.info('setting up twisted reactor in ipython loop')
from twisted.internet import _threadedselect
_threadedselect.install()
from twisted.internet import reactor
from collections import deque
from IPython.lib import inputhook
from IPython import InteractiveShell
q = deque()
def reactor_wake(twisted_loop_next, q=q):
q.append(twisted_loop_next)
def reactor_work(*_args):
if q:
while len(q):
q.popleft()()
return 0
def reactor_start(*_args):
log.info('starting twisted reactor in ipython')
reactor.interleave(reactor_wake) # @UndefinedVariable
inputhook.set_inputhook(reactor_work)
def reactor_stop():
if reactor.threadpool: # @UndefinedVariable
log.info('stopping twisted threads')
reactor.threadpool.stop() # @UndefinedVariable
log.info('shutting down twisted reactor')
reactor._mainLoopShutdown() # @UndefinedVariable
ip = InteractiveShell.instance()
ask_exit = ip.ask_exit
def ipython_exit():
reactor_stop()
return ask_exit()
ip.ask_exit = ipython_exit
reactor_start()
return reactor
示例5: __init__
def __init__(self):
self.cout = io.StringIO()
Term.cout = self.cout
Term.cerr = self.cout
# For debugging, so we can see normal output, use this:
# from IPython.utils.io import Tee
#Term.cout = Tee(self.cout, channel='stdout') # dbg
#Term.cerr = Tee(self.cout, channel='stderr') # dbg
# Create config object for IPython
config = Config()
config.Global.display_banner = False
config.Global.exec_lines = ['import numpy as np',
'from pylab import *'
]
config.InteractiveShell.autocall = False
config.InteractiveShell.autoindent = False
config.InteractiveShell.colors = 'NoColor'
# Create and initialize ipython, but don't start its mainloop
IP = InteractiveShell.instance(config=config)
# Store a few parts of IPython we'll need.
self.IP = IP
self.user_ns = self.IP.user_ns
self.user_global_ns = self.IP.user_global_ns
self.input = ''
self.output = ''
self.is_verbatim = False
self.is_doctest = False
self.is_suppress = False
# on the first call to the savefig decorator, we'll import
# pyplot as plt so we can make a call to the plt.gcf().savefig
self._pyplot_imported = False
# we need bookmark the current dir first so we can save
# relative to it
self.process_input_line('bookmark ipy_basedir')
self.cout.seek(0)
self.cout.truncate(0)
示例6:
from IPython import get_ipython
from IPython import InteractiveShell
shell = InteractiveShell.instance()
ip = get_ipython()
ip.run_cell("%time None")
# CPU times: user 2 µs, sys: 0 ns, total: 2 µs
# Wall time: 3.58 µs