当前位置: 首页>>代码示例>>Python>>正文


Python IPKernelApp.instance方法代码示例

本文整理汇总了Python中IPython.zmq.ipkernel.IPKernelApp.instance方法的典型用法代码示例。如果您正苦于以下问题:Python IPKernelApp.instance方法的具体用法?Python IPKernelApp.instance怎么用?Python IPKernelApp.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPython.zmq.ipkernel.IPKernelApp的用法示例。


在下文中一共展示了IPKernelApp.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pylab_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
 def pylab_kernel(self,gui):
     '''Launch an IPython kernel with pylab support for the gui.'''
     log_debug,pdb,trace = False,True,False
     tag = 'leoIPython.py:pylab_kernel'
     kernel = IPKernelApp.instance()
         # IPKernalApp is a singleton class.
         # Return the singleton instance, creating it if necessary.
     if kernel:
         # pylab is needed for Qt event loop integration.
         args = ['python','--pylab=%s' % (gui)]
         if log_debug: args.append('--debug')
             #'--log-level=10'
             # '--pdb', # User-level debugging
         try:
             if pdb: g.pdb()
             kernel.initialize(args)
             # kernel objects: (Leo --ipython arg)
                 # kernel.session: zmq.session.Session
                 # kernel.shell: ZMQInteractiveShell
                 # kernel.shell.comm_manager: comm.manager.CommManager.
                 # kernel.shell.event = events.EventManager
                 # kernel.shell.run_cell (method)
                 # kernel.shell.hooks
         except Exception:
             sys.stdout = sys.__stdout__
             print('%s: kernel.initialize failed!' % tag)
             raise
     else:
         print('%s IPKernelApp.instance failed' % (tag))
     return kernel
开发者ID:jurov,项目名称:leo-editor,代码行数:32,代码来源:leoIPython.py

示例2: init_ipython

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
def init_ipython():
    """
    Encapsulate Kernel creation logic: Only the kernel client, manager and shell are exposed
    This is in order to ensure interoperability between major IPython changes
    """
    if ipython_1:
        manager = QtInProcessKernelManager()
        manager.start_kernel()
        manager.kernel.gui = 'qt4'
        shell = manager.kernel.shell
        shell.run_cell('%pylab inline')
        client = manager.client()
        client.start_channels()
    else:
        def event_loop(kernel):
            kernel.timer = QTimer()
            kernel.timer.timeout.connect(kernel.do_one_iteration)
            kernel.timer.start(1000 * kernel._poll_interval)

        kernel_app = IPKernelApp.instance()
        kernel_app.initialize(['python', '--pylab=qt'])     # at this point, print() won’t work anymore
        kernel_app.kernel.eventloop = event_loop

        connection_file = find_connection_file(kernel_app.connection_file)
        manager = QtKernelManager(connection_file=connection_file)
        manager.load_connection_file()
        manager.start_channels()

        kernel_app.start()

        client = None
        shell = kernel_app.shell

    return client, manager, shell
开发者ID:hlamer,项目名称:kate,代码行数:36,代码来源:python_console_ipython.py

示例3: pylab_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
def pylab_kernel(gui):
    """Launch and return an IPython kernel with pylab support for the desired gui
    """
    kernel = IPKernelApp.instance()
    kernel.initialize(['python', '--pylab=%s' % gui,
                       '--log-level=10'
                       ])
    return kernel
开发者ID:lichinka,项目名称:cai,代码行数:10,代码来源:with_ipkernel.py

示例4: __init__

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
 def __init__(self):
     self._app = IPKernelApp.instance()
     self._app.initialize()
     fh = logging.FileHandler(self.__class__.__name__ + ".log")
     fh.setLevel(logging.DEBUG)
     log = self._app.kernel.log
     log.setLevel(logging.DEBUG)
     log.addHandler(fh)
     log.debug("kernel init")
开发者ID:imatthewbrown,项目名称:kate,代码行数:11,代码来源:qgdb.py

示例5: pylab_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
def pylab_kernel(gui):
    """Launch and return an IPython kernel with pylab support for the desired gui
    """
    kernel = IPKernelApp.instance()
    # pylab is really needed, for Qt event loop integration
    kernel.initialize(['python', '--pylab=%s' % gui,
                       #'--log-level=10'
                       ])
    return kernel
开发者ID:chiamingyen,项目名称:misc,代码行数:11,代码来源:internal_ipkernel.py

示例6: pylab_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
def pylab_kernel(gui):
    """Launch and return an IPython kernel with pylab support for the desired gui
    """
    kernel = IPKernelApp.instance()
    # Note: pylab command seems to be needed for event loop to behave nicely
    kernel.initialize([get_executable(), '--pylab=%s' % gui,
            "--c='%run -m mantidplotrc'"])
    
    return kernel
开发者ID:trnielsen,项目名称:mantid,代码行数:11,代码来源:internal_ipkernel.py

示例7: fork_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
 def fork_kernel(self, config, pipe, resource_limits, logfile):
     os.setpgrp()
     logging.basicConfig(filename=self.filename,format=str(uuid.uuid4()).split('-')[0]+': %(asctime)s %(message)s',level=logging.DEBUG)
     ka = IPKernelApp.instance(config=config, ip=config["ip"])
     ka.initialize([])
     if self.update_function is not None:
         self.update_function(ka)
     for r, limit in resource_limits.iteritems():
         resource.setrlimit(getattr(resource, r), (limit, limit))
     pipe.send({"ip": ka.ip, "key": ka.session.key, "shell_port": ka.shell_port,
             "stdin_port": ka.stdin_port, "hb_port": ka.hb_port, "iopub_port": ka.iopub_port})
     pipe.close()
     ka.start()
开发者ID:kramer314,项目名称:sagecell,代码行数:15,代码来源:forking_kernel_manager.py

示例8: get_connection_file

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
def get_connection_file(app=None):
    """Return the path to the connection file of an app
    
    Parameters
    ----------
    app : KernelApp instance [optional]
        If unspecified, the currently running app will be used
    """
    if app is None:
        from IPython.zmq.ipkernel import IPKernelApp
        if not IPKernelApp.initialized():
            raise RuntimeError("app not specified, and not in a running Kernel")

        app = IPKernelApp.instance()
    return filefind(app.connection_file, ['.', app.profile_dir.security_dir])
开发者ID:BlackEarth,项目名称:portable-python-win32,代码行数:17,代码来源:kernel.py

示例9: fork_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
 def fork_kernel(self, sage_dict, config, q):
     ka = IPKernelApp.instance(config=config)
     ka.initialize([])
     ka.kernel.shell.user_ns.update(sage_dict)
     ka.kernel.shell.user_ns.update(interact.classes)
     if "sys" in ka.kernel.shell.user_ns:
         ka.kernel.shell.user_ns["sys"]._interacts = interact.interacts
     else:
         sys._interacts = interact.interacts
         ka.kernel.shell.user_ns["sys"] = sys
     ka.kernel.shell.user_ns["interact"] = interact.interact_func(ka.session, ka.iopub_socket)
     q.send({"ip": ka.ip, "key": ka.session.key, "shell_port": ka.shell_port,
             "stdin_port": ka.stdin_port, "hb_port": ka.hb_port, "iopub_port": ka.iopub_port})
     q.close()
     ka.start()
开发者ID:kcrisman,项目名称:sagecell,代码行数:17,代码来源:forking_kernel_manager.py

示例10: pylab_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
 def pylab_kernel(self,gui):
     """Launch and return an IPython kernel with pylab support for the desired gui
     """
     trace = True
     tag = 'leoIPython.py'
     kernel = IPKernelApp.instance()
     if kernel:
         # pylab is really needed, for Qt event loop integration.
         try:
             kernel.initialize(['python','--pylab=%s' % (gui)])
                 #'--log-level=10'
             if trace: print('%s: kernel: %s' % (tag,kernel))
         except Exception:
             print('%s: kernel.initialize failed!' % tag)
             raise
     else:
         print('%s IPKernelApp.instance failed' % (tag))
     return kernel
开发者ID:Armagedoom,项目名称:leo-editor,代码行数:20,代码来源:leoIPython.py

示例11: __init__

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
    def __init__(self, gui, shell):
        self.shell = shell
        self.logger = None

        if shell is None:
            # Start IPython kernel with GUI event loop support
            self.ipkernel = IPKernelApp.instance()
            self.ipkernel.initialize(['python', '--gui=%s' % gui,
                                      #'--log-level=10'  # for debugging
                                      ])
            # This application will also act on the shell user namespace
            self.namespace = self.ipkernel.shell.user_ns

        else:
            self.ipkernel = shell.config.IPKernelApp
            self.namespace = shell.user_ns

        # To create and track active qt consoles
        self.consoles = []
开发者ID:Cadair,项目名称:ginga,代码行数:21,代码来源:ipg.py

示例12: __init__

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
    def __init__(self, gui):
        # Start IPython kernel with GUI event loop support
        self.ipkernel = IPKernelApp.instance()
        self.ipkernel.initialize(['python', '--gui=%s' % gui,
                                  #'--log-level=10'  # for debugging
                                  ])

        # To create and track active qt consoles
        self.consoles = []
        
        # This application will also act on the shell user namespace
        self.namespace = self.ipkernel.shell.user_ns
        # Keys present at startup so we don't print the entire pylab/numpy
        # namespace when the user clicks the 'namespace' button
        self._init_keys = set(self.namespace.keys())

        # Example: a variable that will be seen by the user in the shell, and
        # that the GUI modifies (the 'Counter++' button increments it):
        self.namespace['app_counter'] = 0
开发者ID:ANB2,项目名称:ipython-in-depth,代码行数:21,代码来源:kapp.py

示例13: default_kernel_app

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
def default_kernel_app():
    """ Return a configured IPKernelApp """

    def event_loop(kernel):
        """ Non-blocking qt event loop."""
        kernel.timer = QtCore.QTimer()
        kernel.timer.timeout.connect(kernel.do_one_iteration)
        kernel.timer.start(1000 * kernel._poll_interval)

    app = IPKernelApp.instance()
    try:
        app.initialize(['python', '--pylab=qt'])
    except ZMQError:
        pass  # already set up

    app.kernel.eventloop = event_loop

    try:
        app.start()
    except RuntimeError:  # already started
        pass

    return app
开发者ID:eteq,项目名称:glue,代码行数:25,代码来源:terminal.py

示例14:

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
# Interactive python

from IPython.zmq.ipkernel import IPKernelApp

app = IPKernelApp.instance()
app.initialize([])
app.start()
开发者ID:dbalan,项目名称:Scripts,代码行数:9,代码来源:interactive_shell.py

示例15: _start_kernel

# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import instance [as 别名]
def _start_kernel():
    """starts the ipython kernel and returns the ipython app"""
    from IPython.zmq.ipkernel import IPKernelApp
    from zmq.eventloop import ioloop

    global _kernel_running, _ipython_app
    if _kernel_running:
        return _ipython_app

    # get the app if it exists, or set it up if it doesn't
    if IPKernelApp.initialized():
        app = IPKernelApp.instance()
    else:
        app = IPKernelApp.instance()
        app.initialize()

        # Undo unnecessary sys module mangling from init_sys_modules.
        # This would not be necessary if we could prevent it
        # in the first place by using a different InteractiveShell
        # subclass, as in the regular embed case.
        main = app.kernel.shell._orig_sys_modules_main_mod
        if main is not None:
            sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main

    app.kernel.user_module = sys.modules[__name__]
    app.kernel.user_ns = {}

    # patch in auto-completion support
    # added in https://github.com/ipython/ipython/commit/f4be28f06c2b23cd8e4a3653b9e84bde593e4c86
    # we effectively make the same patches via monkeypatching
    from IPython.core.interactiveshell import InteractiveShell

    old_set_completer_frame = InteractiveShell.set_completer_frame

    # restore old set_completer_frame that gets no-op'd out in ZmqInteractiveShell.__init__
    bound_scf = old_set_completer_frame.__get__(app.shell, InteractiveShell)
    app.shell.set_completer_frame = bound_scf
    app.shell.set_completer_frame()

    # start the kernel
    app.kernel.start()

    # set up a timer to periodically poll the zmq ioloop
    loop = ioloop.IOLoop.instance()

    def poll_ioloop(timer_id, time):
        global _kernel_running

        # if the kernel has been closed then run the event loop until it gets to the
        # stop event added by IPKernelApp.shutdown_request
        if app.kernel.shell.exit_now:
            _log.debug("IPython kernel stopping (%s)" % app.connection_file)
            timer.kill_timer(timer_id)
            ioloop.IOLoop.instance().start()
            _kernel_running = False
            return

        # otherwise call the event loop but stop immediately if there are no pending events
        loop.add_timeout(0, lambda: loop.add_callback(loop.stop))
        ioloop.IOLoop.instance().start()

    _log.debug("IPython kernel starting. Use '--existing %s' to connect." % app.connection_file)
    timer.set_timer(100, poll_ioloop)
    _kernel_running = True

    _ipython_app = app
    return _ipython_app
开发者ID:pyxll,项目名称:pyxll-examples,代码行数:69,代码来源:ipython.py


注:本文中的IPython.zmq.ipkernel.IPKernelApp.instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。