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


Python kernel.KernelManager类代码示例

本文整理汇总了Python中IPython.kernel.KernelManager的典型用法代码示例。如果您正苦于以下问题:Python KernelManager类的具体用法?Python KernelManager怎么用?Python KernelManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setup_client

def setup_client():
    manager = KernelManager()
    #manager.kernel_name = "spread_kernel"
    manager.start_kernel()

    #Setup the client
    client = manager.client()
    client.start_channels()

    #Hijack the IOPub channel
    new_io = MyIOpubChannel(client.context,client.session, client._make_url('iopub'))
    client._iopub_channel = new_io

    #Set up said channel
    client.iopub_channel.start()
    for method in client.iopub_channel.proxy_methods:
        setattr(client, method, getattr(client.iopub_channel, method))

    #Hijack the shell channel
    #old_io_2 = client._shell_channel
    new_shell = MyShellChannel(client.context,client.session, client._make_url('shell'))    
    client._shell_channel = new_shell

    #Set up said channel   
    client.shell_channel.start()
    for method in client.shell_channel.proxy_methods:
        setattr(client, method, getattr(client.shell_channel, method))

    return (manager,client)
开发者ID:A-Malone,项目名称:IPython-spreadsheet,代码行数:29,代码来源:IPython_Interface.py

示例2: __init__

    def __init__(self, notebook_dir, extra_args=None, profile=None,
                 timeout=90):
        self.notebook_dir = os.path.abspath(notebook_dir)
        self.profile = profile
        self.timeout = timeout
        km = KernelManager()
        if extra_args is None:
            extra_args = []
        if profile is not None:
            extra_args += ["--profile=%s" % profile]
        km.start_kernel(stderr=open(os.devnull, 'w'),
                        extra_arguments=extra_args)
        try:
            kc = km.client()
            kc.start_channels()
            iopub = kc.iopub_channel
        except AttributeError: # still on 0.13
            kc = km
            kc.start_channels()
            iopub = kc.sub_channel
        shell = kc.shell_channel
        # make sure it's working
        shell.execute("pass")
        shell.get_msg()

        # all of these should be run pylab inline
        shell.execute("%pylab inline")
        shell.get_msg()

        self.kc = kc
        self.km = km
        self.iopub = iopub
开发者ID:Autodidact24,项目名称:statsmodels,代码行数:32,代码来源:nbgenerate.py

示例3: start_new_kernel

def start_new_kernel():
    """start a new kernel, and return its Manager and Client"""
    km = KernelManager()
    km.start_kernel(stdout=PIPE, stderr=PIPE)
    kc = km.client()
    kc.start_channels()
    
    msg_id = kc.kernel_info()
    kc.get_shell_msg(block=True, timeout=STARTUP_TIMEOUT)
    flush_channels(kc)
    return km, kc
开发者ID:AJRenold,项目名称:ipython,代码行数:11,代码来源:utils.py

示例4: setup

def setup():
    global KM, KC
    KM = KernelManager()
    KM.start_kernel(stdout=PIPE, stderr=PIPE)
    KC = KM.client()
    KC.start_channels()
    
    # wait for kernel to be ready
    KC.execute("pass")
    KC.get_shell_msg(block=True, timeout=5)
    flush_channels()
开发者ID:Jim4,项目名称:ipython,代码行数:11,代码来源:test_message_spec.py

示例5: start_new_kernel

def start_new_kernel(argv=None):
    """start a new kernel, and return its Manager and Client"""
    km = KernelManager()
    kwargs = dict(stdout=nose.iptest_stdstreams_fileno(), stderr=STDOUT)
    if argv:
        kwargs['extra_arguments'] = argv
    km.start_kernel(**kwargs)
    kc = km.client()
    kc.start_channels()

    msg_id = kc.kernel_info()
    kc.get_shell_msg(block=True, timeout=STARTUP_TIMEOUT)
    flush_channels(kc)
    return km, kc
开发者ID:pyarnold,项目名称:ipython,代码行数:14,代码来源:utils.py

示例6: km_from_string

def km_from_string(s=''):
    """create kernel manager from IPKernelApp string
    such as '--shell=47378 --iopub=39859 --stdin=36778 --hb=52668' for IPython 0.11
    or just 'kernel-12345.json' for IPython 0.12
    """
    global km, kc, send

    from os.path import join as pjoin
    from IPython.config.loader import KeyValueConfigLoader

    try:
        from IPython.kernel import (
            KernelManager,
            find_connection_file,
        )
    except ImportError:
        from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
        from IPython.zmq.kernelapp import kernel_aliases
        from IPython.lib.kernel import find_connection_file

        s = s.replace('--existing', '')

        if '--profile' in s:
            k,p = s.split('--profile')
            k = k.lstrip().rstrip() # kernel part of the string
            p = p.lstrip().rstrip() # profile part of the string
            fullpath = find_connection_file(k,p)
        else:
            fullpath = find_connection_file(s.lstrip().rstrip())

        km = KernelManager(connection_file = fullpath)
        km.load_connection_file()
        km.start_channels()
        send = km.shell_channel.execute # not sure if this should be changed as well

        respond(None, "python.client.error.ipython-version", None)
        return


    s = s.replace('--existing', '')

    if '--profile' in s:
        k,p = s.split('--profile')
        k = k.lstrip().rstrip() # kernel part of the string
        p = p.lstrip().rstrip() # profile part of the string
        fullpath = find_connection_file(k,p)
    else:
        fullpath = find_connection_file(s.lstrip().rstrip())

    km = KernelManager(connection_file = fullpath)
    km.load_connection_file()
    kc = km.client()
    kc.start_channels()
    send = kc.execute
    return km
开发者ID:smason,项目名称:Python,代码行数:55,代码来源:ltipy.py

示例7: execute_kernel

def execute_kernel(nb, t, tshell):
    """
    Load Kernel stuff

    iopub may be necessary to run through the cell
    """
    km = KernelManager()
    km.start_kernel(extra_arguments=['--matplotlib=inline'],
                    stderr=open(os.devnull, 'w'))
    try:
        kc = km.client()
        kc.start_channels()
        iopub = kc.iopub_channel
    except AttributeError:
        # IPython 0.13
        kc = km
        kc.start_channels()
        iopub = kc.sub_channel
    shell = kc.shell_channel

    """
    This part needs revision
    """
    # run %pylab inline, because some notebooks assume this
    # even though they shouldn't
    shell.execute("pass")
    shell.get_msg()
    while True:
        try:
            iopub.get_msg(timeout=1)
        except Empty:
            break

    """
    Try to print cell by cell
    """
    # Only one worksheet in the current ipython nbs structure
    for cell in nb.worksheets[0].cells:

        # If the cell is code, move to next cell
        if cell.cell_type != 'code':
            continue

        # Otherwise the cell is an output cell, run it!
        try:
            outs = run_cell(shell, iopub, cell, t, tshell)
            print outs
        except Exception as e:
            print "failed to run cell:", repr(e)
            print cell.input
开发者ID:davidcortesortuno,项目名称:pytest_validate_nb,代码行数:50,代码来源:kernel_testing.py

示例8: setup

def setup():
    global KM, KC
    KM = KernelManager()
    KM.start_kernel(stdout=PIPE, stderr=PIPE)
    KC = KM.client()
    KC.start_channels()
    
    # wait for kernel to be ready
    try:
        msg = KC.iopub_channel.get_msg(block=True, timeout=STARTUP_TIMEOUT)
    except Empty:
        pass
    msg_id = KC.kernel_info()
    KC.get_shell_msg(block=True, timeout=STARTUP_TIMEOUT)
    flush_channels()
开发者ID:IMHu624,项目名称:ipython,代码行数:15,代码来源:test_message_spec.py

示例9: new_ipy

def new_ipy(s=''):
    """Create a new IPython kernel (optionally with extra arguments)

    XXX: Allow passing of profile information here

    Examples
    --------

        new_ipy()

    """
    from IPython.kernel import KernelManager
    km = KernelManager()
    km.start_kernel()
    return km_from_string(km.connection_file)
开发者ID:demis001,项目名称:dot-files,代码行数:15,代码来源:vim_ipython.py

示例10: __enter__

    def __enter__(self):
        self.km = KernelManager()
        self.km.start_kernel(extra_arguments=self.extra_arguments, stderr=open(os.devnull, 'w'))

        try:
            self.kc = self.km.client()
            self.kc.start_channels()
            self.iopub = self.kc.iopub_channel
        except AttributeError:
            # IPython 0.13
            self.kc = self.km
            self.kc.start_channels()
            self.iopub = self.kc.sub_channel

        self.shell = self.kc.shell_channel

        # run %pylab inline, because some notebooks assume this
        # even though they shouldn't
        self.shell.execute("pass")
        self.shell.get_msg()
        while True:
            try:
                self.iopub.get_msg(timeout=1)
            except Empty:
                break

        return self
开发者ID:bmiles,项目名称:assaytools,代码行数:27,代码来源:ipnbdoctest.py

示例11: __init__

    def __init__(self, **kw):
        """Initializes the notebook runner.
           Requires config rcloud_python_lib_path -- or raises exception"""
        self.km = KernelManager()
        self.km.kernel_cmd = make_ipkernel_cmd("""
import sys; 
sys.path.extend("{RCPATH}".split(":")); 
from rcloud_kernel import main; 
main()""".format(RCPATH=kw["rcloud_python_lib_path"]), **kw)
        del kw["rcloud_python_lib_path"]
        self.km.client_factory = MyClient
        self.km.start_kernel(**kw)

        if platform.system() == 'Darwin':
            # There is sometimes a race condition where the first
            # execute command hits the kernel before it's ready.
            # It appears to happen only on Darwin (Mac OS) and an
            # easy (but clumsy) way to mitigate it is to sleep
            # for a second.
            sleep(1)

        self.kc = self.km.client()
        self.kc.start_channels()

        self.shell = self.kc.shell_channel
        self.iopub = self.kc.iopub_channel
开发者ID:nareshbab,项目名称:rcloud,代码行数:26,代码来源:notebook_runner.py

示例12: __init__

    def __init__(self, nb_in=None, pylab=False, mpl_inline=False, nb=None):
        self.km = KernelManager()
        if pylab:
            self.km.start_kernel(extra_arguments=['--pylab=inline'])
        elif mpl_inline:
            self.km.start_kernel(extra_arguments=['--matplotlib=inline'])
        else:
            self.km.start_kernel()

        if platform.system() == 'Darwin':
            # There is sometimes a race condition where the first
            # execute command hits the kernel before it's ready.
            # It appears to happen only on Darwin (Mac OS) and an
            # easy (but clumsy) way to mitigate it is to sleep
            # for a second.
            sleep(1)

        self.kc = self.km.client()
        self.kc.start_channels()

        self.shell = self.kc.shell_channel
        self.iopub = self.kc.iopub_channel

        logging.info('Reading notebook %s', nb_in)
        
        self.nb = nb
        
        if not self.nb:
            self.nb = read(open(nb_in), 'json')
开发者ID:adamhaney,项目名称:runipy,代码行数:29,代码来源:notebook_runner.py

示例13: __init__

    def __init__(self, **kw):
        """Initializes the notebook runner.
           Requires config rcloud_python_lib_path -- or raises exception"""
        self.km = KernelManager()
        self.km.kernel_cmd = make_ipkernel_cmd("""
import sys; 
import time; # to test for slow staring kernels, add a delay here
sys.path.extend("{RCPATH}".split(":")); 
from rcloud_kernel import main; 
main()""".format(RCPATH=kw["rcloud_python_lib_path"]), **kw)
        del kw["rcloud_python_lib_path"]
        self.km.client_factory = MyClient
        self.km.start_kernel(**kw) # This is a non-blocking call to launch the process
        self.completer = completer.Completer()
        self.completer.limit_to__all__ = True
        # There is a possible race condition if the system is slow to load
        # the modules for the kernel and we issue commands to the kernel rightaway.
        # We saw these on CentOS and OSX. So, issue an empty command to the kernel and wait for return
        self.kc = self.km.client()
        self.kc.start_channels()

        self.shell = self.kc.shell_channel
        self.shell.execute("")
        _ = self.shell.get_msgs()
        self.iopub = self.kc.iopub_channel
开发者ID:FelipeJColon,项目名称:rcloud,代码行数:25,代码来源:notebook_runner.py

示例14: __init__

 def __init__(self):
     self.km = KernelManager()
     self.km.start_kernel(stderr=open(os.devnull, 'w'))
     self.kc = self.km.client()
     self.kc.start_channels()
     self.shell = self.kc.shell_channel
     self.shell.execute("pass")
     self.shell.get_msg()
开发者ID:takluyver,项目名称:pytest_validate_nb,代码行数:8,代码来源:original_test.py

示例15: __init__

    def __init__(
            self,
            nb,
            pylab=False,
            mpl_inline=False,
            profile_dir=None,
            working_dir=None):

        self.first_cell = True

        self.km = KernelManager()

        args = []

        if pylab:
            args.append('--pylab=inline')
            logging.warn(
                '--pylab is deprecated and will be removed in a future version'
            )
        elif mpl_inline:
            args.append('--matplotlib=inline')
            logging.warn(
                '--matplotlib is deprecated and' +
                ' will be removed in a future version'
            )

        if profile_dir:
            args.append('--profile-dir=%s' % os.path.abspath(profile_dir))

        cwd = os.getcwd()

        if working_dir:
            os.chdir(working_dir)

        self.km.start_kernel(extra_arguments=args)

        os.chdir(cwd)

        if platform.system() == 'Darwin':
            # There is sometimes a race condition where the first
            # execute command hits the kernel before it's ready.
            # It appears to happen only on Darwin (Mac OS) and an
            # easy (but clumsy) way to mitigate it is to sleep
            # for a second.
            sleep(1)

        self.kc = self.km.client()
        self.kc.start_channels()
        try:
            self.kc.wait_for_ready()
        except AttributeError:
            # IPython < 3
            self._wait_for_ready_backport()

        self.nb = nb
开发者ID:kantale,项目名称:runipy,代码行数:55,代码来源:notebook_runner.py


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