當前位置: 首頁>>代碼示例>>Python>>正文


Python ipkernel.IPKernelApp類代碼示例

本文整理匯總了Python中IPython.zmq.ipkernel.IPKernelApp的典型用法代碼示例。如果您正苦於以下問題:Python IPKernelApp類的具體用法?Python IPKernelApp怎麽用?Python IPKernelApp使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IPKernelApp類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: InternalIPKernel

class InternalIPKernel(object):
    """Class for managing an IPython kernel inside of QGIS.

    IPython normally runs kernels in seperate processes, but this setup is
    limiting in the case of QGIS because external kernels cannot access the
    data and variables that QGIS is working with. This class manages an
    in-process kernel and is capable of launching external consoles that can
    attach to the kernel.

    IPython Consoles are run as external processes because they rely on
    Version 2 of the PyQt api and QGIS is using Version 1 which is
    incompatible.
    """
    def __init__(self):
        self.ipkernel = IPKernelApp()
        self.ipkernel.initialize(['python',
            # Ensure the Kernel pre-loads the same modules as are available
            # from the QGIS python console.
            "--c='from qgis.core import *;import qgis.utils;'"])
        # Ensure we use an event loop that is QGIS-friendly.
        self.ipkernel.kernel.eventloop = loop_qgis
        self.ipkernel.start()

        # To create and track active qt consoles
        self._qtconsole_cmd = ['ipython', 'qtconsole', '--existing'] + \
                [os.path.basename(self.ipkernel.connection_file)]
        self.consoles = []

    def new_qt_console(self, evt=None):
        self.consoles.append(subprocess.Popen(self._qtconsole_cmd))

    def cleanup_consoles(self, evt=None):
        for c in self.consoles:
            c.kill()
開發者ID:carriercomm,項目名稱:qgis-ipython,代碼行數:34,代碼來源:internal_ipkernel.py

示例2: pylab_kernel

def pylab_kernel(gui):
    """Launch and return an IPython kernel with pylab support for the desired gui
    """
    kernel = IPKernelApp()
    kernel.initialize(['python', '--pylab=%s' % gui,
                       #'--log-level=10'
                       ])
    return kernel
開發者ID:AhmedPho,項目名稱:ipython,代碼行數:8,代碼來源:internal_ipkernel.py

示例3: pylab_kernel

def pylab_kernel(gui):
    """Launch and return an IPython kernel with pylab support for the desired gui
    """
    kernel = IPKernelApp()
    # FIXME: we're hardcoding the heartbeat port b/c of a bug in IPython 0.11
    # that will set it to 0 if not specified.  Once this is fixed, the --hb
    # parameter can be omitted and all ports will be automatic
    kernel.initialize(['python', '--pylab=%s' % gui, '--hb=19999',
                       #'--log-level=10'
                       ])
    return kernel
開發者ID:Paolopost,項目名稱:fos,代碼行數:11,代碼來源:fosapp.py

示例4: get_connection_file

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,代碼行數:15,代碼來源:kernel.py

示例5: pylab_kernel

 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,代碼行數:30,代碼來源:leoIPython.py

示例6: init_ipython

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,代碼行數:34,代碼來源:python_console_ipython.py

示例7: bind_kernel

def bind_kernel(**kwargs):
    """Bind an Engine's Kernel to be used as a full IPython kernel.
    
    This allows a running Engine to be used simultaneously as a full IPython kernel
    with the QtConsole or other frontends.
    
    This function returns immediately.
    """
    from IPython.zmq.ipkernel import IPKernelApp
    from IPython.parallel.apps.ipengineapp import IPEngineApp
    
    # first check for IPKernelApp, in which case this should be a no-op
    # because there is already a bound kernel
    if IPKernelApp.initialized() and isinstance(IPKernelApp._instance, IPKernelApp):
        return
    
    if IPEngineApp.initialized():
        try:
            app = IPEngineApp.instance()
        except MultipleInstanceError:
            pass
        else:
            return app.bind_kernel(**kwargs)
    
    raise RuntimeError("bind_kernel be called from an IPEngineApp instance")
開發者ID:fccoelho,項目名稱:ipython,代碼行數:25,代碼來源:__init__.py

示例8: __init__

 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,代碼行數:9,代碼來源:qgdb.py

示例9: pylab_kernel

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,代碼行數:9,代碼來源:internal_ipkernel.py

示例10: pylab_kernel

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,代碼行數:9,代碼來源:internal_ipkernel.py

示例11: fork_kernel

 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,代碼行數:13,代碼來源:forking_kernel_manager.py

示例12: __init__

    def __init__(self):
        self.ipkernel = IPKernelApp()
        self.ipkernel.initialize(['python',
            # Ensure the Kernel pre-loads the same modules as are available
            # from the QGIS python console.
            "--c='from qgis.core import *;import qgis.utils;'"])
        # Ensure we use an event loop that is QGIS-friendly.
        self.ipkernel.kernel.eventloop = loop_qgis
        self.ipkernel.start()

        # To create and track active qt consoles
        self._qtconsole_cmd = ['ipython', 'qtconsole', '--existing'] + \
                [os.path.basename(self.ipkernel.connection_file)]
        self.consoles = []
開發者ID:carriercomm,項目名稱:qgis-ipython,代碼行數:14,代碼來源:internal_ipkernel.py

示例13: fork_kernel

 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,代碼行數:15,代碼來源:forking_kernel_manager.py

示例14: pylab_kernel

 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,代碼行數:18,代碼來源:leoIPython.py

示例15: __init__

    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,代碼行數:19,代碼來源:ipg.py


注:本文中的IPython.zmq.ipkernel.IPKernelApp類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。