當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。