コード例 #1
0
ファイル: thread_pool.py プロジェクト: zghzdxs/veles
 def sigint_handler(sign, frame):
     """
     Private method - handler for SIGINT.
     """
     ThreadPool.interrupted = True
     ThreadPool.shutdown_pools(execute_remaining=False, force=True)
     log = logging.getLogger("ThreadPool")
     try:
         # ThreadPool.sigint_initial(sign, frame) does not work on Python 2
         sigint_initial = ThreadPool.__dict__['sigint_initial']
         if sigint_initial == ThreadPool.sigint_handler:
             log.warning("Prevented an infinite recursion: sigint_initial")
         else:
             sigint_initial(sign, frame)
     except KeyboardInterrupt:
         if not reactor.running:
             if not ThreadPool.sigint_printed:
                 log.warning("Raising KeyboardInterrupt since "
                             "Twisted reactor is not running")
                 ThreadPool.sigint_printed = True
                 raise from_none(KeyboardInterrupt())
             ThreadPool._warn_about_sigint_hysteria(log)
         else:
             if not ThreadPool.sigint_printed:
                 log.critical("KeyboardInterrupt")
                 ThreadPool.debug_deadlocks()
                 ThreadPool.sigint_printed = True
             else:
                 if not is_interactive():
                     ThreadPool._warn_about_sigint_hysteria(log)
                 else:
                     ThreadPool._warn_about_sigint_interactive_reactor(log)
コード例 #2
0
ファイル: thread_pool.py プロジェクト: 2php/veles
 def sigint_handler(sign, frame):
     """
     Private method - handler for SIGINT.
     """
     ThreadPool.interrupted = True
     ThreadPool.shutdown_pools(execute_remaining=False, force=True)
     log = logging.getLogger("ThreadPool")
     try:
         # ThreadPool.sigint_initial(sign, frame) does not work on Python 2
         sigint_initial = ThreadPool.__dict__['sigint_initial']
         if sigint_initial == ThreadPool.sigint_handler:
             log.warning("Prevented an infinite recursion: sigint_initial")
         else:
             sigint_initial(sign, frame)
     except KeyboardInterrupt:
         if not reactor.running:
             if not ThreadPool.sigint_printed:
                 log.warning("Raising KeyboardInterrupt since "
                             "Twisted reactor is not running")
                 ThreadPool.sigint_printed = True
                 raise from_none(KeyboardInterrupt())
             ThreadPool._warn_about_sigint_hysteria(log)
         else:
             if not ThreadPool.sigint_printed:
                 log.critical("KeyboardInterrupt")
                 ThreadPool.debug_deadlocks()
                 ThreadPool.sigint_printed = True
             else:
                 if not is_interactive():
                     ThreadPool._warn_about_sigint_hysteria(log)
                 else:
                     ThreadPool._warn_about_sigint_interactive_reactor(log)
コード例 #3
0
ファイル: __init__.py プロジェクト: zghzdxs/veles
    def __call__(self, workflow, config=None, *args, **kwargs):
        """
        Launcher the specified workflow and returns the corresponding
        :class:`veles.launcher.Launcher` instance.
        If there exists a standard input, returns immediately after the
        workflow is initialized; otherwise, blocks until it finishes.
        If this command runs under IPython, it's local variables are passed
        into the workflow's :meth:`__init__()`.
        If "subprocess" keyword argument is set to True, runs in a separate
        process.

        Arguments:
            workflow: path to the Python file with workflow definition.
            config: path to the workflow configuration. If None, *_config.py
                    is taken.
            kwargs: arguments to be passed as if "veles" is executed from the
                    command line. They match the command line arguments except
                    that "-" must be substituted with "_". For example,
                    "backend" -> "--backend", random_seed -> "--random-seed".
                    See "veles --help" for the complete list.

        Returns:
            veles.launcher.Launcher instance which can be used to manage the
            execution (e.g., pause() and resume()); if "subprocess" was set to
            True, a started multiprocessing.Process instance is returned
            instead, which can be join()-ed.
        """
        if kwargs.get("subprocess", False):
            del kwargs["subprocess"]
            from multiprocessing import Process
            proc = Process(target=self.__call__,
                           name="veles.__call__",
                           args=(workflow, config) + args,
                           kwargs=kwargs)
            proc.start()
            return proc
        # FIXME(v.markovtsev): disable R0401 locally when pylint issue is fixed
        # https://bitbucket.org/logilab/pylint/issue/61
        # from veles.__main__ import Main  # pylint: disable=R0401
        Main = import_module("veles.__main__").Main
        if config is None:
            config = "-"
        if "interactive" in kwargs:
            interactive = kwargs["interactive"]
            del kwargs["interactive"]
        else:
            interactive = is_interactive()
        main = Main(interactive, workflow, config, *args, **kwargs)
        main.run()
        return main.launcher
コード例 #4
0
ファイル: __init__.py プロジェクト: 2php/veles
    def __call__(self, workflow, config=None, *args, **kwargs):
        """
        Launcher the specified workflow and returns the corresponding
        :class:`veles.launcher.Launcher` instance.
        If there exists a standard input, returns immediately after the
        workflow is initialized; otherwise, blocks until it finishes.
        If this command runs under IPython, it's local variables are passed
        into the workflow's :meth:`__init__()`.
        If "subprocess" keyword argument is set to True, runs in a separate
        process.

        Arguments:
            workflow: path to the Python file with workflow definition.
            config: path to the workflow configuration. If None, *_config.py
                    is taken.
            kwargs: arguments to be passed as if "veles" is executed from the
                    command line. They match the command line arguments except
                    that "-" must be substituted with "_". For example,
                    "backend" -> "--backend", random_seed -> "--random-seed".
                    See "veles --help" for the complete list.

        Returns:
            veles.launcher.Launcher instance which can be used to manage the
            execution (e.g., pause() and resume()); if "subprocess" was set to
            True, a started multiprocessing.Process instance is returned
            instead, which can be join()-ed.
        """
        if kwargs.get("subprocess", False):
            del kwargs["subprocess"]
            from multiprocessing import Process
            proc = Process(target=self.__call__, name="veles.__call__",
                           args=(workflow, config) + args, kwargs=kwargs)
            proc.start()
            return proc
        # FIXME(v.markovtsev): disable R0401 locally when pylint issue is fixed
        # https://bitbucket.org/logilab/pylint/issue/61
        # from veles.__main__ import Main  # pylint: disable=R0401
        Main = import_module("veles.__main__").Main
        if config is None:
            config = "-"
        if "interactive" in kwargs:
            interactive = kwargs["interactive"]
            del kwargs["interactive"]
        else:
            interactive = is_interactive()
        main = Main(interactive, workflow, config, *args, **kwargs)
        main.run()
        return main.launcher
コード例 #5
0
ファイル: thread_pool.py プロジェクト: zghzdxs/veles
 def restore_initial_interactive_exit():
     if not is_interactive():
         return
     try:
         __IPYTHON__  # pylint: disable=E0602
         from IPython.terminal.interactiveshell import InteractiveShell
         shell = InteractiveShell.instance()
         shell.exiter.__call__ = ThreadPool.exit_initial
         shell.ask_exit = ThreadPool._ipython_ask_exit_initial
     except NameError:
         try:
             import builtins
             builtins.exit = ThreadPool.exit_initial
             builtins.quit = ThreadPool.quit_initial
         except:
             pass
コード例 #6
0
ファイル: thread_pool.py プロジェクト: 2php/veles
 def restore_initial_interactive_exit():
     if not is_interactive():
         return
     try:
         __IPYTHON__  # pylint: disable=E0602
         from IPython.terminal.interactiveshell import InteractiveShell
         shell = InteractiveShell.instance()
         shell.exiter.__call__ = ThreadPool.exit_initial
         shell.ask_exit = ThreadPool._ipython_ask_exit_initial
     except NameError:
         try:
             import builtins
             builtins.exit = ThreadPool.exit_initial
             builtins.quit = ThreadPool.quit_initial
         except:
             pass