Пример #1
0
    def run(self):
        # tell ipython to use gevent as the mainloop
        inputhook_manager.set_inputhook(inputhook_gevent)

        # initialize clients
        for name, info in self._ports.iteritems():
            port = info.get('rpc')
            if port is None:
                continue
            heartbeat = info.get('rpcHeartbeat', 5)
            timeout = info.get('rpcTimeout', 99999)
            client = zerorpc.Client(port, heartbeat=heartbeat, timeout=timeout)
            # immediately set up simple proxy
            globals()[name] = ClientProxy(name, client)
            if not self._opts.command:
                # set up background task to construct decorated proxy that replaces
                # simple proxy
                gevent.spawn(self.setDecoratedProxy, name, client)

        if self._opts.command:
            exec(self._opts.command)
            gevent.sleep(0.1)
            sys.exit(0)

        services = sorted(self._ports.keys())
        servicesStr = '\n'.join(['  %s' % svc for svc in services])
        intro = INTRO_TEMPLATE % {'services': servicesStr}
        ipshell = InteractiveShellEmbed(config=Config(), banner1=intro)
        ipshell()
Пример #2
0
    def run(self):
        # tell ipython to use gevent as the mainloop
        inputhook_manager.set_inputhook(inputhook_gevent)

        # initialize clients
        for name, info in self._ports.iteritems():
            port = info.get('rpc')
            if port is None:
                continue
            heartbeat = info.get('rpcHeartbeat', 5)
            timeout = info.get('rpcTimeout', 99999)
            client = zerorpc.Client(port,
                                    heartbeat=heartbeat,
                                    timeout=timeout)
            # immediately set up simple proxy
            globals()[name] = ClientProxy(name, client)
            if not self._opts.command:
                # set up background task to construct decorated proxy that replaces
                # simple proxy
                gevent.spawn(self.setDecoratedProxy, name, client)

        if self._opts.command:
            exec(self._opts.command)
            gevent.sleep(0.1)
            sys.exit(0)

        services = sorted(self._ports.keys())
        servicesStr = '\n'.join(['  %s' % svc for svc in services])
        intro = INTRO_TEMPLATE % {'services': servicesStr}
        ipshell = InteractiveShellEmbed(config=Config(),
                                        banner1=intro)
        ipshell()
Пример #3
0
    def setup_ipython_shell(shell_api=None):
        ipy_config = _setup_ipython_config()

        # monkeypatch the ipython inputhook to be gevent-friendly
        import gevent  # should be auto-monkey-patched by pyon already.
        import select
        import sys
        import os

        def stdin_ready():
            infds, outfds, erfds = select.select([sys.stdin], [], [], 0)
            if infds:
                return True
            else:
                return False

        def inputhook_gevent():
            try:
                while not stdin_ready():
                    gevent.sleep(0.05)
            except KeyboardInterrupt:
                pass

            return 0

        # install the gevent inputhook
        from IPython.lib.inputhook import inputhook_manager
        inputhook_manager.set_inputhook(inputhook_gevent)
        inputhook_manager._current_gui = 'gevent'

        # First import the embeddable shell class
        from IPython.frontend.terminal.embed import InteractiveShellEmbed
        from mock import patch

        # Update namespace of interactive shell
        # TODO: Cleanup namespace even further
        if shell_api is not None:
            locals().update(shell_api)

        # Now create an instance of the embeddable shell. The first argument is a
        # string with options exactly as you would type them if you were starting
        # IPython at the system command line. Any parameters you want to define for
        # configuration can thus be specified here.
        with patch(
                "IPython.core.interactiveshell.InteractiveShell.init_virtualenv"
        ):
            ipshell = InteractiveShellEmbed(config=ipy_config,
                banner1 =\
                """              ____                                ________  _   __   ____________   ____  ___
             / __ \__  ______  ____              /  _/ __ \/ | / /  / ____/ ____/  / __ \|__ \\
            / /_/ / / / / __ \/ __ \   ______    / // / / /  |/ /  / /   / /      / /_/ /__/ /
           / ____/ /_/ / /_/ / / / /  /_____/  _/ // /_/ / /|  /  / /___/ /___   / _, _// __/
          /_/    \__, /\____/_/ /_/           /___/\____/_/ |_/   \____/\____/  /_/ |_|/____/
                /____/""",
                exit_msg = 'Leaving ION shell, shutting down container.')

            ipshell(
                'Pyon (PID: %s) - ION R2 CC interactive IPython shell. Type ionhelp() for help'
                % os.getpid())
Пример #4
0
def breakpoint(scope=None):
    from IPython.config.loader import Config
    ipy_config = Config()
    ipy_config.PromptManager.in_template = '><> '
    ipy_config.PromptManager.in2_template = '... '
    ipy_config.PromptManager.out_template = '--> '
    ipy_config.InteractiveShellEmbed.confirm_exit = False

    # monkeypatch the ipython inputhook to be gevent-friendly
    import gevent   # should be auto-monkey-patched by pyon already.
    import select
    import sys

    def stdin_ready():
        infds, outfds, erfds = select.select([sys.stdin], [], [], 0)
        if infds:
            return True
        else:
            return False

    def inputhook_gevent():
        try:
            while not stdin_ready():
                gevent.sleep(0.05)
        except KeyboardInterrupt:
            pass

        return 0

    # install the gevent inputhook
    from IPython.lib.inputhook import inputhook_manager
    inputhook_manager.set_inputhook(inputhook_gevent)
    inputhook_manager._current_gui = 'gevent'

    # First import the embeddable shell class
    from IPython.frontend.terminal.embed import InteractiveShellEmbed
    from mock import patch
    if scope is not None:
        from pyon.container.shell_api import get_shell_api
        from pyon.container.cc import Container
        locals().update(scope)
        if Container.instance:
            locals().update(get_shell_api(Container.instance))

    # Update namespace of interactive shell
    # TODO: Cleanup namespace even further
    # Now create an instance of the embeddable shell. The first argument is a
    # string with options exactly as you would type them if you were starting
    # IPython at the system command line. Any parameters you want to define for
    # configuration can thus be specified here.
    with patch("IPython.core.interactiveshell.InteractiveShell.init_virtualenv"):
        ipshell = InteractiveShellEmbed(config=ipy_config,
                banner1="Entering Breakpoint Shell",
            exit_msg = 'Returning...')

        stack = traceback.extract_stack(limit=2)
        message = 'File %s, line %s, in %s' % stack[0][:-1]

        ipshell('Breakpoint @ ' + message)
Пример #5
0
def setup_ipython(shell_api=None):
    from IPython.config.loader import Config
    ipython_cfg = Config()
    shell_config = ipython_cfg.InteractiveShellEmbed
    shell_config.prompt_in1 = '><> '
    shell_config.prompt_in2 = '... '
    shell_config.prompt_out = '--> '
    shell_config.confirm_exit = False

    # monkeypatch the ipython inputhook to be gevent-friendly
    import gevent   # should be auto-monkey-patched by pyon already.
    import select
    import sys
    def stdin_ready():
        infds, outfds, erfds = select.select([sys.stdin], [], [], 0)
        if infds:
            return True
        else:
            return False

    def inputhook_gevent():
        try:
            while not stdin_ready():
                gevent.sleep(0.05)
        except KeyboardInterrupt:
            pass

        return 0

    # install the gevent inputhook
    from IPython.lib.inputhook import inputhook_manager
    inputhook_manager.set_inputhook(inputhook_gevent)
    inputhook_manager._current_gui = 'gevent'

    # First import the embeddable shell class
    from IPython.frontend.terminal.embed import InteractiveShellEmbed

    # Update namespace of interactive shell
    # TODO: Cleanup namespace even further
    if shell_api is not None:
        locals().update(shell_api)

    # Now create an instance of the embeddable shell. The first argument is a
    # string with options exactly as you would type them if you were starting
    # IPython at the system command line. Any parameters you want to define for
    # configuration can thus be specified here.
    ipshell = InteractiveShellEmbed(config=ipython_cfg,
        banner1 =\
        """      ____                                ________  _   __   ____________   ____  ___
     / __ \__  ______  ____              /  _/ __ \/ | / /  / ____/ ____/  / __ \|__ \\
    / /_/ / / / / __ \/ __ \   ______    / // / / /  |/ /  / /   / /      / /_/ /__/ /
   / ____/ /_/ / /_/ / / / /  /_____/  _/ // /_/ / /|  /  / /___/ /___   / _, _// __/
  /_/    \__, /\____/_/ /_/           /___/\____/_/ |_/   \____/\____/  /_/ |_|/____/
        /____/""",
        exit_msg = 'Leaving ION shell, shutting down container.')

    ipshell('Pyon - ION R2 CC interactive IPython shell. Type ionhelp() for help')
Пример #6
0
 def debug_shell(self, app):
     """
     Variant of :meth:`run_forever` that drops us into an IPython shell
     """
     from IPython.terminal.ipapp import TerminalIPythonApp
     ip = TerminalIPythonApp.instance()
     ip.initialize(argv=[])
     ip.shell.user_global_ns['app'] = app
     def ipy_import(module_name, identifier):
         module = importlib.import_module(module_name)
         ip.shell.user_global_ns[identifier] = getattr(module, identifier) 
     #ipy_import('sage_notebook.model.git_interface', 'GitInterface')
     from IPython.lib.inputhook import inputhook_manager
     inputhook_manager.set_inputhook(self.ipython_inputhook)
     ip.start()
Пример #7
0
 def set_event_loop():
     loop = InputEventLoop()
     asyncio.set_event_loop(loop)
     inputhook_manager.set_inputhook(loop.hook)
     loop._running = True
Пример #8
0
Файл: pycc.py Проект: ooici/pyon
    def setup_ipython_shell(shell_api=None):
        if not _exists_ipython_dir():
            log.warn("IPython profile dir not found. Attempting to avoid race condition")
            import gevent
            import random

            gevent.sleep(random.random() * 3.0)  # Introduce a random delay to make conflict less likely

        ipy_config = _setup_ipython_config()

        # monkeypatch the ipython inputhook to be gevent-friendly
        import gevent  # should be auto-monkey-patched by pyon already.
        import select

        def stdin_ready():
            infds, outfds, erfds = select.select([sys.stdin], [], [], 0)
            if infds:
                return True
            else:
                return False

        def inputhook_gevent():
            try:
                while not stdin_ready():
                    gevent.sleep(0.05)
            except KeyboardInterrupt:
                pass

            return 0

        # install the gevent inputhook
        from IPython.lib.inputhook import inputhook_manager

        inputhook_manager.set_inputhook(inputhook_gevent)
        inputhook_manager._current_gui = "gevent"

        # First import the embeddable shell class
        from IPython.frontend.terminal.embed import InteractiveShellEmbed
        from mock import patch

        # Update namespace of interactive shell
        # TODO: Cleanup namespace even further
        if shell_api is not None:
            locals().update(shell_api)

        # Now create an instance of the embeddable shell. The first argument is a
        # string with options exactly as you would type them if you were starting
        # IPython at the system command line. Any parameters you want to define for
        # configuration can thus be specified here.
        with patch("IPython.core.interactiveshell.InteractiveShell.init_virtualenv"):
            for tries in range(3):
                try:
                    ipshell = InteractiveShellEmbed(
                        config=ipy_config,
                        banner1="""           ____  ____  _____   __     __     ____________
          / __ \/ __ \/  _/ | / /__  / /_   / ____/ ____/
         / / / / / / // //  |/ / _ \/ __/  / /   / /
        / /_/ / /_/ // // /|  /  __/ /_   / /___/ /___
        \____/\____/___/_/ |_/\___/\__/   \____/\____/""",
                        exit_msg="Leaving OOINet CC shell, shutting down container.",
                    )

                    ipshell(
                        "Pyon (PID: %s) - OOINet CC interactive IPython shell. Type ionhelp() for help" % os.getpid()
                    )
                    break
                except Exception as ex:
                    log.debug("Failed IPython initialize attempt (try #%s): %s", tries, str(ex))
                    import gevent
                    import random

                    gevent.sleep(random.random() * 0.5)
Пример #9
0
This is an IPython shell with the pyraptord zerorpc service bound to the
"d" variable. You can run commands like d.startService("mytask").
"""

ipshell = InteractiveShellEmbed(config=Config(),
                                banner1=INTRO)


def inputhook_gevent():
    try:
        while not stdin_ready():
            gevent.sleep(0.05)
    except KeyboardInterrupt:
        pass
    return 0

# tell ipython to use gevent as the mainloop
inputhook_manager.set_inputhook(inputhook_gevent)


class Shell(object):
    def __init__(self, configPath):
        self._config = loadConfig(configPath)
        self._ports = loadConfig(self._config.PORTS)

    def run(self):
        port = self._ports.pyraptord.rpc
        print 'connecting to pyraptord at %s' % port
        d = zerorpc.Client(port)  # pylint: disable=W0612
        ipshell()
Пример #10
0
This is an IPython shell with the pyraptord zerorpc service bound to the
"d" variable. You can run commands like d.startService("mytask").
"""

ipshell = InteractiveShellEmbed(config=Config(), banner1=INTRO)


def inputhook_gevent():
    try:
        while not stdin_ready():
            gevent.sleep(0.05)
    except KeyboardInterrupt:
        pass
    return 0


# tell ipython to use gevent as the mainloop
inputhook_manager.set_inputhook(inputhook_gevent)


class Shell(object):
    def __init__(self, configPath):
        self._config = loadConfig(configPath)
        self._ports = loadConfig(self._config.PORTS)

    def run(self):
        port = self._ports.pyraptord.rpc
        print 'connecting to pyraptord at %s' % port
        d = zerorpc.Client(port)  # pylint: disable=W0612
        ipshell()
Пример #11
0
    def setup_ipython_shell(shell_api=None):
        if not _exists_ipython_dir():
            log.warn(
                "IPython profile dir not found. Attempting to avoid race condition"
            )
            import gevent
            import random
            gevent.sleep(
                random.random() *
                3.0)  # Introduce a random delay to make conflict less likely

        ipy_config = _setup_ipython_config()

        # monkeypatch the ipython inputhook to be gevent-friendly
        import gevent  # should be auto-monkey-patched by pyon already.
        import select

        def stdin_ready():
            infds, outfds, erfds = select.select([sys.stdin], [], [], 0)
            if infds:
                return True
            else:
                return False

        def inputhook_gevent():
            try:
                while not stdin_ready():
                    gevent.sleep(0.05)
            except KeyboardInterrupt:
                pass

            return 0

        # install the gevent inputhook
        # See also https://github.com/ipython/ipython/pull/1654
        from IPython.lib.inputhook import inputhook_manager
        inputhook_manager.set_inputhook(inputhook_gevent)
        inputhook_manager._current_gui = 'gevent'

        # First import the embeddable shell class
        from IPython.terminal.embed import InteractiveShellEmbed
        from mock import patch

        # Update namespace of interactive shell
        # TODO: Cleanup namespace even further
        if shell_api is not None:
            locals().update(shell_api)

        # Now create an instance of the embeddable shell. The first argument is a
        # string with options exactly as you would type them if you were starting
        # IPython at the system command line. Any parameters you want to define for
        # configuration can thus be specified here.
        with patch(
                "IPython.core.interactiveshell.InteractiveShell.init_virtualenv"
        ):
            for tries in range(3):
                try:
                    ipshell = InteractiveShellEmbed(
                        banner1=
                        """           _____      _ ____  _   __   ____________
          / ___/_____(_) __ \/ | / /  / ____/ ____/
          \__ \/ ___/ / / / /  |/ /  / /   / /     
         ___/ / /__/ / /_/ / /|  /  / /___/ /___   
        /____/\___/_/\____/_/ |_/   \____/\____/""",
                        exit_msg=
                        'Leaving SciON CC shell, shutting down container.',
                        **ipy_config)

                    ipshell(
                        'SciON CC IPython shell. PID: %s. Type ionhelp() for help'
                        % os.getpid())
                    break
                except Exception as ex:
                    log.debug(
                        "Failed IPython initialize attempt (try #%s): %s",
                        tries, str(ex))
                    import gevent
                    import random
                    gevent.sleep(random.random() * 0.5)
Пример #12
0
def breakpoint(scope=None, global_scope=None):
    from IPython.config.loader import Config
    ipy_config = Config()
    ipy_config.PromptManager.in_template = '><> '
    ipy_config.PromptManager.in2_template = '... '
    ipy_config.PromptManager.out_template = '--> '
    ipy_config.InteractiveShellEmbed.confirm_exit = False

    # monkeypatch the ipython inputhook to be gevent-friendly
    import gevent  # should be auto-monkey-patched by pyon already.
    import select
    import sys

    def stdin_ready():
        infds, outfds, erfds = select.select([sys.stdin], [], [], 0)
        if infds:
            return True
        else:
            return False

    def inputhook_gevent():
        try:
            while not stdin_ready():
                gevent.sleep(0.05)
        except KeyboardInterrupt:
            pass

        return 0

    # install the gevent inputhook
    from IPython.lib.inputhook import inputhook_manager
    inputhook_manager.set_inputhook(inputhook_gevent)
    inputhook_manager._current_gui = 'gevent'

    # First import the embeddable shell class
    from IPython.frontend.terminal.embed import InteractiveShellEmbed
    from mock import patch
    if scope is not None:
        from pyon.container.shell_api import get_shell_api
        from pyon.container.cc import Container
        locals().update(scope)
        locals().update({'bt': get_stack})
        if Container.instance:
            locals().update(get_shell_api(Container.instance))
    if global_scope is not None:
        globals().update(global_scope)

    from pyon.core.bootstrap import get_sys_name

    # Update namespace of interactive shell
    # TODO: Cleanup namespace even further
    # Now create an instance of the embeddable shell. The first argument is a
    # string with options exactly as you would type them if you were starting
    # IPython at the system command line. Any parameters you want to define for
    # configuration can thus be specified here.
    with patch(
            "IPython.core.interactiveshell.InteractiveShell.init_virtualenv"):
        ipshell = InteractiveShellEmbed(config=ipy_config,
                                        banner1="Entering Breakpoint Shell",
                                        exit_msg='Returning...')

        stack = traceback.extract_stack(limit=2)
        message = 'File %s, line %s, in %s' % stack[0][:-1]

        ipshell('(%s) Breakpoint @ %s' % (get_sys_name(), message))
Пример #13
0
 def set_event_loop():
     loop = InputEventLoop()
     asyncio.set_event_loop(loop)
     inputhook_manager.set_inputhook(loop.hook)
     loop._running = True