本文整理汇总了Python中IPython.terminal.embed.InteractiveShellEmbed.mainloop方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed.mainloop方法的具体用法?Python InteractiveShellEmbed.mainloop怎么用?Python InteractiveShellEmbed.mainloop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.embed.InteractiveShellEmbed
的用法示例。
在下文中一共展示了InteractiveShellEmbed.mainloop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ipython_console
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
def ipython_console():
"""
Run ipython console
"""
from traitlets.config import Config
from IPython.terminal.embed import InteractiveShellEmbed
config = Config()
# basic configuration
config.TerminalInteractiveShell.confirm_exit = False
#
embed = InteractiveShellEmbed(config=config, banner1='')
embed.mainloop()
示例2: make_shell
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
def make_shell(banner=u'IPython', **namespace):
cfg = Config()
prompt_config = cfg.PromptManager
prompt_config.in_template = r'{color.LightGreen}\[email protected]\h{color.LightBlue}[{color.LightCyan}\Y1{color.LightBlue}]{color.Green}|\#> '
prompt_config.out_template = r'<\#> '
sh = InteractiveShellEmbed(config=cfg, banner1=banner)
return sh.mainloop(local_ns=namespace)
示例3: debughook
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
def debughook(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
else:
# we are NOT in interactive mode, print the exception...
#traceback.print_exception(type, value, tb)
colorhook(type, value, tb)
frame = tb.tb_next.tb_frame
sh = InteractiveShellEmbed(
banner1=termcolor.colored(
"Custom Debug IPython Shell:\n", 'red'))
sh.confirm_exit = False
sh.mainloop(local_ns=frame.f_locals, global_ns=frame.f_globals)
示例4: InteractiveShellEmbed
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
from IPython.terminal.embed import InteractiveShellEmbed
shell = InteractiveShellEmbed(user_ns=_env)
shell()
return
elif IPython.__version__ >= '0.11':
from IPython.frontend.terminal.embed import InteractiveShellEmbed
shell = InteractiveShellEmbed(user_ns=_env)
shell()
return
else:
# following 2 lines fix a problem with
# IPython; thanks Michael Toomim
if '__builtins__' in _env:
del _env['__builtins__']
shell = IPython.Shell.IPShell(argv=[], user_ns=_env)
shell.mainloop()
return
except:
logger.warning(
'import IPython error; use default python shell')
enable_autocomplete_and_history(adir,_env)
code.interact(local=_env)
def parse_path_info(path_info, av=False):
"""
Parse path info formatted like a/c/f where c and f are optional
and a leading / accepted.
Return tuple (a, c, f). If invalid path_info a is set to None.
If c or f are omitted they are set to None.
If av=True, parse args and vars
示例5: process_argv
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
def process_argv(argv):
"""
Process command-line arguments (minus argv[0]!), rearrange and execute.
"""
# Initial preparation
import __main__
for (k,v) in global_constants.items():
exec '%s = %s' % (k,v) in __main__.__dict__
# Allow param.normalize_path.prefix to be overridden in the
# startup files, but otherwise force it to exist before doing
# anything else
param.normalize_path.prefix = default_output_path()
exec_startup_files()
set_output_path(param.normalize_path.prefix)
# Tell the user how many cores are in use, if available
openmp_main=Parameterized(name="OpenMP") # Dummy object just for messages
try:
import os,multiprocessing
total_cores = multiprocessing.cpu_count()
num_threads = int(os.environ.get('OMP_NUM_THREADS',total_cores))
openmp_main.verbose("Using %d threads on a machine with %d detected CPUs" % (num_threads, total_cores))
except:
pass
# Repeatedly process options, if any, followed by filenames, if any, until nothing is left
topo_parser.disable_interspersed_args()
args=argv
option=None
global something_executed
while True:
# Process options up until the first filename
(option,args) = topo_parser.parse_args(args,option)
# Handle filename
if args:
filename=args.pop(0)
#print "Executing %s" % (filename)
filedir = os.path.dirname(os.path.abspath(filename))
sys.path.insert(0,filedir) # Allow imports relative to this file's path
sim_name_from_filename(filename) # Default value of topo.sim.name
execfile(filename,__main__.__dict__)
something_executed=True
if not args:
break
global_params.check_for_unused_names()
# If no scripts and no commands were given, pretend -i was given.
if not something_executed: interactive()
if option.gui: topo.guimain.title(topo.sim.name)
## INTERACTIVE SESSION BEGINS HERE (i.e. can't have anything but
## some kind of cleanup code afterwards)
if os.environ.get('PYTHONINSPECT'):
print "Output path: %s" % param.normalize_path.prefix
print BANNER
# CBALERT: should probably allow a way for users to pass
# things to IPython? Or at least set up some kind of
# topographica ipython config file. Right now, a topo_parser
# option has to be added for every ipython option we want to
# support (e.g. see --pdb)
if ipython_shell_interface == "IPython.Shell":
# IPython 0.10 and earlier
# Stop IPython namespace hack?
# http://www.nabble.com/__main__-vs-__main__-td14606612.html
__main__.__name__="__mynamespace__"
ipython_args = ['-noconfirm_exit','-nobanner',
'-pi1',CommandPrompt.get_format(),
'-pi2',CommandPrompt2.get_format(),
'-po',OutputPrompt.get_format()]
if option.pdb:
ipython_args.append('-pdb')
ipshell = IPShell(ipython_args,user_ns=__main__.__dict__)
ipshell.mainloop(sys_exit=1)
elif ipython_shell_interface == "InteractiveShellEmbed":
# IPython 0.11 and later
config = Config()
if ipython_prompt_interface == "PromptManager":
config.PromptManager.in_template = CommandPrompt.get_format()
config.PromptManager.in2_template = CommandPrompt2.get_format()
config.PromptManager.out_template = OutputPrompt.get_format()
else:
config.InteractiveShell.prompt_in1 = CommandPrompt.get_format()
config.InteractiveShell.prompt_in2 = CommandPrompt2.get_format()
config.InteractiveShell.prompt_out = OutputPrompt.get_format()
config.InteractiveShell.confirm_exit = False
ipshell = IPShell(config=config,user_ns=__main__.__dict__,
banner1="",exit_msg="")
#.........这里部分代码省略.........
示例6: Device
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
You can script the device's SCSI interface too:
sc c ac # Backdoor signature
sc 8 ff 00 ff # Undocumented firmware version
ALSO: reset, eject, sc_sense, sc_read, scsi_in, scsi_out
Happy hacking! -- Type 'thing?' for help on 'thing' or
~MeS`14 '?' for IPython, '%h' for this again.
"""
from IPython.terminal.embed import InteractiveShellEmbed
from shell_magics import ShellMagics
from remote import Device
import shell_namespace
# Make a global device, but only give it to the user namespace.
# Make it default by assigning it to 'd', our current device.
shell_namespace.d = shell_namespace.d_remote = Device()
# Make a shell that feels like a debugger
ipy = InteractiveShellEmbed(user_ns = shell_namespace.__dict__)
shell_namespace.ipy = ipy
ipy.register_magics(ShellMagics)
ipy.register_magic_function(lambda _: ipy.write(__doc__), magic_name='h')
ipy.alias_manager.define_alias('git', 'git')
ipy.alias_manager.define_alias('make', 'make')
# Hello, tiny world
ipy.mainloop(display_banner = __doc__)
示例7: Device
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
~MeS`14 '?' for IPython, '%h' for this again.
"""
from IPython.terminal.embed import InteractiveShellEmbed
from shell_magics import ShellMagics
from remote import Device
import shell_namespace
messages = ''
# Make a global device, but only give it to the user namespace.
# Make it default by assigning it to 'd', our current device.
try:
shell_namespace.d = shell_namespace.d_remote = Device()
except IOError, e:
messages += "\n-------- There is NO DEVICE available! --------\n"
messages += "\n%s\n\n" % e
messages += "--> Try again to attach via USB: %reset\n"
messages += "--> Reattach over bitbang serial: %bitbang -a /dev/tty.usb<tab>\n"
shell_namespace.d = shell_namespace.d_remote = None
# Make a shell that feels like a debugger
ipy = InteractiveShellEmbed(user_ns = shell_namespace.__dict__)
shell_namespace.ipy = ipy
ipy.register_magics(ShellMagics)
ipy.register_magic_function(lambda _: ipy.write(__doc__), magic_name='h')
ipy.alias_manager.define_alias('git', 'git')
ipy.alias_manager.define_alias('make', 'make')
# Hello, tiny world
ipy.mainloop(display_banner = __doc__ + messages)
示例8: run
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import mainloop [as 别名]
#.........这里部分代码省略.........
'modules', 'cron', 'errors', 'sessions',
'languages', 'static', 'private', 'uploads']:
subpath = os.path.join(adir, subfolder)
if not os.path.exists(subpath):
os.mkdir(subpath)
db = os.path.join(adir, 'models/db.py')
if os.path.exists(db):
data = fileutils.read_file(db)
data = data.replace(
'<your secret key>', 'sha512:' + web2py_uuid())
fileutils.write_file(db, data)
if c:
import_models = True
extra_request = {}
if args:
extra_request['args'] = args
if vars:
extra_request['vars'] = vars
_env = env(a, c=c, f=f, import_models=import_models, extra_request=extra_request)
if c:
pyfile = os.path.join('applications', a, 'controllers', c + '.py')
pycfile = os.path.join('applications', a, 'compiled',
"controllers_%s_%s.pyc" % (c, f))
if ((cronjob and os.path.isfile(pycfile))
or not os.path.isfile(pyfile)):
exec(read_pyc(pycfile), _env)
elif os.path.isfile(pyfile):
execfile(pyfile, _env)
else:
die(errmsg)
if f:
exec('print %s()' % f, _env)
return
_env.update(exec_pythonrc())
if startfile:
try:
ccode = None
if startfile.endswith('.pyc'):
ccode = read_pyc(startfile)
exec(ccode, _env)
else:
execfile(startfile, _env)
if import_models:
BaseAdapter.close_all_instances('commit')
except Exception as e:
print(traceback.format_exc())
if import_models:
BaseAdapter.close_all_instances('rollback')
elif python_code:
try:
exec(python_code, _env)
if import_models:
BaseAdapter.close_all_instances('commit')
except Exception as e:
print(traceback.format_exc())
if import_models:
BaseAdapter.close_all_instances('rollback')
else:
if not plain:
if bpython:
try:
import bpython
bpython.embed(locals_=_env)
return
except:
logger.warning(
'import bpython error; trying ipython...')
else:
try:
import IPython
if IPython.__version__ > '1.0.0':
IPython.start_ipython(user_ns=_env)
return
elif IPython.__version__ == '1.0.0':
from IPython.terminal.embed import InteractiveShellEmbed
shell = InteractiveShellEmbed(user_ns=_env)
shell()
return
elif IPython.__version__ >= '0.11':
from IPython.frontend.terminal.embed import InteractiveShellEmbed
shell = InteractiveShellEmbed(user_ns=_env)
shell()
return
else:
# following 2 lines fix a problem with
# IPython; thanks Michael Toomim
if '__builtins__' in _env:
del _env['__builtins__']
shell = IPython.Shell.IPShell(argv=[], user_ns=_env)
shell.mainloop()
return
except:
logger.warning(
'import IPython error; use default python shell')
enable_autocomplete_and_history(adir, _env)
code.interact(local=_env)