예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
 def format_kernel_cmd(self, **kw):
     """format templated args (e.g. {connection_file})"""
     if self.kernel_cmd:
         cmd = self.kernel_cmd
     else:
         cmd = make_ipkernel_cmd(
             'from IPython.kernel.zmq.kernelapp import main; main()', **kw)
     ns = dict(connection_file=self.connection_file)
     ns.update(self._launch_args)
     return [c.format(**ns) for c in cmd]
예제 #6
0
파일: manager.py 프로젝트: AlfiyaZi/ipython
 def format_kernel_cmd(self, **kw):
     """format templated args (e.g. {connection_file})"""
     if self.kernel_cmd:
         cmd = self.kernel_cmd
     else:
         cmd = make_ipkernel_cmd(
             'from IPython.kernel.zmq.kernelapp import main; main()',
             **kw
         )
     ns = dict(connection_file=self.connection_file)
     ns.update(self._launch_args)
     return [ c.format(**ns) for c in cmd ]
예제 #7
0
    def format_kernel_cmd(self, **kw):
        """replace templated args (e.g. {connection_file})"""
        if self.kernel_cmd:
            cmd = self.kernel_cmd
        else:
            cmd = make_ipkernel_cmd(
                'from IPython.kernel.zmq.kernelapp import main; main()', **kw)
        ns = dict(connection_file=self.connection_file)
        ns.update(self._launch_args)

        pat = re.compile(r'\{([A-Za-z0-9_]+)\}')

        def from_ns(match):
            """Get the key out of ns if it's there, otherwise no change."""
            return ns.get(match.group(1), match.group())

        return [pat.sub(from_ns, arg) for arg in cmd]
예제 #8
0
 def format_kernel_cmd(self, **kw):
     """replace templated args (e.g. {connection_file})"""
     if self.kernel_cmd:
         cmd = self.kernel_cmd
     else:
         cmd = make_ipkernel_cmd(
             'from IPython.kernel.zmq.kernelapp import main; main()',
             **kw
         )
     ns = dict(connection_file=self.connection_file)
     ns.update(self._launch_args)
     
     pat = re.compile(r'\{([A-Za-z0-9_]+)\}')
     def from_ns(match):
         """Get the key out of ns if it's there, otherwise no change."""
         return ns.get(match.group(1), match.group())
     
     return [ pat.sub(from_ns, arg) for arg in cmd ]
예제 #9
0
    def __init__(self, **kw):
        self.km = KernelManager()
        self.km.kernel_cmd = make_ipkernel_cmd('import sys; sys.path.append("%s"); from rcloud_kernel import main; main()' % kw["rcloud_support_path"], **kw)
        del kw["rcloud_support_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
예제 #10
0
    def format_kernel_cmd(self, **kw):
        """replace templated args (e.g. {connection_file})"""
        if self.kernel_cmd:
            cmd = self.kernel_cmd
        elif self.kernel_name == "python":
            # The native kernel gets special handling
            cmd = make_ipkernel_cmd("from IPython.kernel.zmq.kernelapp import main; main()", **kw)
        else:
            cmd = self.kernel_spec.argv

        ns = dict(connection_file=self.connection_file)
        ns.update(self._launch_args)

        pat = re.compile(r"\{([A-Za-z0-9_]+)\}")

        def from_ns(match):
            """Get the key out of ns if it's there, otherwise no change."""
            return ns.get(match.group(1), match.group())

        return [pat.sub(from_ns, arg) for arg in cmd]
예제 #11
0
    def __init__(self, **kw):
        self.km = KernelManager()
        self.km.kernel_cmd = make_ipkernel_cmd(
            'import sys; sys.path.append("%s"); from rcloud_kernel import main; main()' % kw["rcloud_support_path"],
            **kw
        )
        del kw["rcloud_support_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