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


Python signal.SIGTSTP属性代码示例

本文整理汇总了Python中signal.SIGTSTP属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGTSTP属性的具体用法?Python signal.SIGTSTP怎么用?Python signal.SIGTSTP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在signal的用法示例。


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

示例1: pause_children

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def pause_children(self, names=None):
        # send pause signal to alive children
        if names is None:
            names = self.conns_from_children.keys()

        logger.debug("Pausing %s", str(names))

        for name in names:
            assert name in self.child_states  # check it's a real child
            proc = self.child_processes[name]
            if proc.is_alive():
                try:
                    process = psutil.Process(pid=proc.pid)
                    try:
                        for child in process.children(recursive=True):
                            try:
                                child.send_signal(signal.SIGTSTP)
                            except (psutil.NoSuchProcess, psutil.AccessDenied, IOError):
                                pass
                    except (psutil.NoSuchProcess, psutil.AccessDenied, IOError) as e:
                        logger.warn("Error %s getting children for pause for child %s", e.strerror, name)
                    process.send_signal(signal.SIGTSTP)
                    logger.info("Paused %s", name)
                except (psutil.NoSuchProcess, psutil.AccessDenied, IOError):  # child may have terminated
                    pass 
开发者ID:jamesrobertlloyd,项目名称:automl-phase-2,代码行数:27,代码来源:agent.py

示例2: save

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def save(self):
        """Save important things to file"""
        self.flag.value = 2

        logger.info("Saving")
        # Ignore sigtstp messages from now on:
        signal.signal(signal.SIGTSTP, self.signal_ignore)

        # Saving only happens on the first CPU
        p = psutil.Process()
        current_cpus = p.cpu_affinity()
        if len(current_cpus) > 1:
            p.cpu_affinity([current_cpus[0]])

        # Save children
        self.save_children(save_timeout=300)

        # Save myself
        with open(self.save_file, 'wb') as pickle_file:
            pickle.dump(self, pickle_file, pickle.HIGHEST_PROTOCOL)

        logger.info("Completed saving")
        self.flag.value = 3 
开发者ID:jamesrobertlloyd,项目名称:automl-phase-2,代码行数:25,代码来源:agent.py

示例3: ignore_user_entered_signals

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def ignore_user_entered_signals():
    """
    Ignores user entered signals to avoid process getting killed.
    """
    if is_windows:
        signal_list = [signal.SIGINT]
    else:
        signal_list = [signal.SIGINT, signal.SIGQUIT, signal.SIGTSTP]
    actual_signals = []
    for user_signal in signal_list:
        actual_signals.append(signal.signal(user_signal, signal.SIG_IGN))
    try:
        yield
    finally:
        for sig, user_signal in enumerate(signal_list):
            signal.signal(user_signal, actual_signals[sig]) 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:18,代码来源:compat.py

示例4: __init__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def __init__(self, name, pid_dir='/var/run', signals=None):
        """
        Constructor.

        ``name`` is a string that identifies the daemon. The name is
        used for the name of the daemon process, the PID file and for
        the messages to syslog.

        ``pid_dir`` is the directory in which the PID file is stored.

        ``signals`` list of operating signals, that should be available
        for use with :py:meth:`.send_signal`, :py:meth:`.got_signal`,
        :py:meth:`.wait_for_signal`, and :py:meth:`.check_signal`. Note
        that SIGTERM is always supported, and that SIGTTIN, SIGTTOU, and
        SIGTSTP are never supported.
        """
        self.name = name
        self.pid_file = _PIDFile(os.path.join(pid_dir, name + '.pid'))
        self._signal_events = {int(s): threading.Event()
                               for s in ((signals or []) + [signal.SIGTERM])}
        self.logger = logging.getLogger(name)
        if not self.logger.handlers:
            self.logger.addHandler(logging.NullHandler())
        self.files_preserve = [] 
开发者ID:torfsen,项目名称:service,代码行数:26,代码来源:__init__.py

示例5: _cleanup_worker

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def _cleanup_worker(self, signum, frame):
        """Handle cleanup when the process is sent a signal.

        This will handle releasing tasks in flight and deleting tasks that have
        been completed.
        """
        logger.info('Process sent signal %d. Cleaning up tasks...' % signum)

        num_completed, num_incomplete = self._release_batch()

        # When the process is suspended we release tasks and then return to the
        # main loop.
        if signum == signal.SIGTSTP:
            self._on_sigtstp(num_completed, num_incomplete)
            return
        else:
            # Allow the client of this library to do any setup before
            # shutting down the worker.
            settings.ON_WORKER_SHUTDOWN()
            self._on_shutdown(num_completed, num_incomplete)
            sys.exit(0) 
开发者ID:Nextdoor,项目名称:ndkale,代码行数:23,代码来源:worker.py

示例6: make_default_signal_map

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def make_default_signal_map():
    """ Make the default signal map for this system.

        The signals available differ by system. The map will not
        contain any signals not defined on the running system.

        """
    name_map = {
        'SIGTSTP': None,
        'SIGTTIN': None,
        'SIGTTOU': None,
        'SIGTERM': 'terminate',
        }
    signal_map = dict(
        (getattr(signal, name), target)
        for (name, target) in name_map.items()
        if hasattr(signal, name))

    return signal_map 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:daemon.py

示例7: make_default_signal_map

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def make_default_signal_map():
    """ Make the default signal map for this system.

        The signals available differ by system. The map will not
        contain any signals not defined on the running system.

        """
    name_map = {
        'SIGTSTP': None,
        'SIGTTIN': None,
        'SIGTTOU': None,
        'SIGTERM': 'terminate',
    }
    signal_map = dict(
        (getattr(signal, name), target)
        for (name, target) in name_map.items()
        if hasattr(signal, name))

    return signal_map 
开发者ID:candlepin,项目名称:virt-who,代码行数:21,代码来源:daemon.py

示例8: __enter__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def __enter__(self):
        # Make sure to cleanup GPIO afterward
        if not self.__signals_trapped:
            self.__signals_trapped = True
            for sig in [signal.SIGQUIT, signal.SIGTERM, signal.SIGTSTP]:
                if hasattr(signal.getsignal(sig), '__call__'):
                    deleg = signal.getsignal(sig)

                    def delegate(signum, stack):
                        self.__exit__(None, None, None)
                        deleg(signum, stack)

                    signal.signal(sig, delegate)
                else:
                    def delegate(signum, stack):
                        self.__exit__(None, None, None)

                    signal.signal(sig, delegate)
        return self 
开发者ID:ke4roh,项目名称:RPiNWR,代码行数:21,代码来源:AIWIBoardContext.py

示例9: suspend_to_background

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def suspend_to_background(self, suspend_group=True):
        """
        (Not thread safe -- to be called from inside the key bindings.)
        Suspend process.

        :param suspend_group: When true, suspend the whole process group.
            (This is the default, and probably what you want.)
        """
        # Only suspend when the opperating system supports it.
        # (Not on Windows.)
        if hasattr(signal, 'SIGTSTP'):
            def run():
                # Send `SIGSTP` to own process.
                # This will cause it to suspend.

                # Usually we want the whole process group to be suspended. This
                # handles the case when input is piped from another process.
                if suspend_group:
                    os.kill(0, signal.SIGTSTP)
                else:
                    os.kill(os.getpid(), signal.SIGTSTP)

            self.run_in_terminal(run) 
开发者ID:bkerler,项目名称:android_universal,代码行数:25,代码来源:interface.py

示例10: test_default_rewrites_can_be_overriden_with_setsid_enabled

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def test_default_rewrites_can_be_overriden_with_setsid_enabled():
    """In setsid mode, dumb-init should allow overwriting the default
    rewrites (but still suspend itself).
    """
    rewrite_map = {
        signal.SIGTTIN: signal.SIGTERM,
        signal.SIGTTOU: signal.SIGINT,
        signal.SIGTSTP: signal.SIGHUP,
    }
    with print_signals(_rewrite_map_to_args(rewrite_map)) as (proc, _):
        for send, expect_receive in rewrite_map.items():
            assert process_state(proc.pid) in ['running', 'sleeping']
            proc.send_signal(send)

            assert proc.stdout.readline() == '{}\n'.format(expect_receive).encode('ascii')
            os.waitpid(proc.pid, os.WUNTRACED)
            assert process_state(proc.pid) == 'stopped'

            proc.send_signal(signal.SIGCONT)
            assert proc.stdout.readline() == '{}\n'.format(signal.SIGCONT).encode('ascii')
            assert process_state(proc.pid) in ['running', 'sleeping'] 
开发者ID:Yelp,项目名称:dumb-init,代码行数:23,代码来源:proxies_signals_test.py

示例11: _catch_interrupt

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def _catch_interrupt(signal_no, frame):
            """
            SIGINT handler.  We ignore the signal and frame info passed in.
            """
            # Stop pep-8 shouting at me for unused params I can't control.
            del frame

            # The OS already caught the ctrl-c, so inject it now for the next
            # input.
            if signal_no == signal.SIGINT:
                curses.ungetch(3)
            elif signal_no == signal.SIGTSTP:
                curses.ungetch(26) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:15,代码来源:screen.py

示例12: test_catch_exceptions

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def test_catch_exceptions(self):
        """
        Check that we can catch exceptions (e.g. for ctrl-c).
        """
        def internal_checks(screen):
            # Not much we can do here as refresh will draw to a screen we can't
            # query. Check that we don't hit an Exception on refresh().
            if sys.platform == "win32":
                # Strictly speaking, this doesn't test catching ctrl-c as
                # it isn't possible to trigger the control handler (even if
                # we don't catch interrupts).  Still a good basic check for
                # input, though.
                event = win32console.PyINPUT_RECORDType(win32console.KEY_EVENT)
                event.Char = u"\03"
                event.KeyDown = 1
                event.RepeatCount = 1
                event.ControlKeyState = win32con.LEFT_CTRL_PRESSED
                event.VirtualKeyCode = 67
                event.VirtualScanCode = 46
                screen._stdin.WriteConsoleInput([event])
                event.KeyDown = 0
                screen._stdin.WriteConsoleInput([event])
                ch = screen.get_event()
                self.assertEqual(ch.key_code, 3)
                self.assertIsNone(screen.get_event())
            else:
                # Check Ctrl-c (and no other input)
                os.kill(os.getpid(), signal.SIGINT)
                ch = screen.get_event()
                self.assertEqual(ch.key_code, 3)
                self.assertIsNone(screen.get_event())

                # Check Ctrl-z (and no other input)
                os.kill(os.getpid(), signal.SIGTSTP)
                ch = screen.get_event()
                self.assertEqual(ch.key_code, 26)
                self.assertIsNone(screen.get_event())

        Screen.wrapper(internal_checks, height=15, catch_interrupt=True) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:41,代码来源:test_screen.py

示例13: __init__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def __init__(self, app):
        super(Console, self).__init__(app)
        self.interrupt = Event()
        gevent.signal(signal.SIGTSTP, self.interrupt.set)
        self.console_locals = [] 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:7,代码来源:console_service.py

示例14: handleInput

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def handleInput(self, char):
        #log.msg('handling %s' % repr(char))
        if char in ('\n', '\r'):
            self.escapeMode = 1
            self.write(char)
        elif self.escapeMode == 1 and char == options['escape']:
            self.escapeMode = 2
        elif self.escapeMode == 2:
            self.escapeMode = 1 # so we can chain escapes together
            if char == '.': # disconnect
                log.msg('disconnecting from escape')
                stopConnection()
                return
            elif char == '\x1a': # ^Z, suspend
                def _():
                    _leaveRawMode()
                    sys.stdout.flush()
                    sys.stdin.flush()
                    os.kill(os.getpid(), signal.SIGTSTP)
                    _enterRawMode()
                reactor.callLater(0, _)
                return
            elif char == 'R': # rekey connection
                log.msg('rekeying connection')
                self.conn.transport.sendKexInit()
                return
            elif char == '#': # display connections
                self.stdio.write('\r\nThe following connections are open:\r\n')
                channels = self.conn.channels.keys()
                channels.sort()
                for channelId in channels:
                    self.stdio.write('  #%i %s\r\n' % (channelId, str(self.conn.channels[channelId])))
                return
            self.write('~' + char)
        else:
            self.escapeMode = 0
            self.write(char) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:39,代码来源:conch.py

示例15: _catch_interrupt

# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGTSTP [as 别名]
def _catch_interrupt(signal_no, frame):
            """
            SIGINT handler.  We ignore the signal and frame info passed in.
            """
            # Stop pep-8 shouting at me for unused params I can't control.
            del frame

            # The OS already caught the ctrl-c, so inject it now for the next
            # input.
            if signal_no == signal.SIGINT:
                curses.ungetch(3)
            elif signal_no == signal.SIGTSTP:
                curses.ungetch(26)
            return 
开发者ID:QData,项目名称:deepWordBug,代码行数:16,代码来源:screen.py


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