當前位置: 首頁>>代碼示例>>Python>>正文


Python signal.SIGHUP屬性代碼示例

本文整理匯總了Python中signal.SIGHUP屬性的典型用法代碼示例。如果您正苦於以下問題:Python signal.SIGHUP屬性的具體用法?Python signal.SIGHUP怎麽用?Python signal.SIGHUP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在signal的用法示例。


在下文中一共展示了signal.SIGHUP屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_SIGHUP_tty

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def test_SIGHUP_tty(self):
        # When not daemonized, SIGHUP should shut down the server.
        try:
            from signal import SIGHUP
        except ImportError:
            return self.skip('skipped (no SIGHUP) ')

        # Spawn the process.
        p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
        p.write_conf(
            extra='test_case_name: "test_SIGHUP_tty"')
        p.start(imports='cherrypy.test._test_states_demo')
        # Send a SIGHUP
        os.kill(p.get_pid(), SIGHUP)
        # This might hang if things aren't working right, but meh.
        p.join() 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:18,代碼來源:test_states.py

示例2: enable_death_signal

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def enable_death_signal(_warn=True):
    """
    Set the "death signal" of the current process, so that
    the current process will be cleaned with guarantee
    in case the parent dies accidentally.
    """
    if platform.system() != 'Linux':
        return
    try:
        import prctl    # pip install python-prctl
    except ImportError:
        if _warn:
            log_once('"import prctl" failed! Install python-prctl so that processes can be cleaned with guarantee.',
                     'warn')
        return
    else:
        assert hasattr(prctl, 'set_pdeathsig'), \
            "prctl.set_pdeathsig does not exist! Note that you need to install 'python-prctl' instead of 'prctl'."
        # is SIGHUP a good choice?
        prctl.set_pdeathsig(signal.SIGHUP) 
開發者ID:tensorpack,項目名稱:dataflow,代碼行數:22,代碼來源:concurrency.py

示例3: _test_restart_service_on_sighup

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def _test_restart_service_on_sighup(self, service, workers=1):
        self._start_server(callback=service, workers=workers)
        os.kill(self.service_pid, signal.SIGHUP)
        expected_msg = (
            test_server.FAKE_START_MSG * workers +
            test_server.FAKE_RESET_MSG * (workers + 1))
        expected_size = len(expected_msg)

        utils.wait_until_true(
            lambda: (os.path.isfile(self.temp_file) and
                     os.stat(self.temp_file).st_size ==
                     expected_size),
            timeout=5, sleep=0.1,
            exception=RuntimeError(
                "Timed out waiting for file %(filename)s to be created and "
                "its size become equal to %(size)s." %
                {'filename': self.temp_file,
                 'size': expected_size}))
        with open(self.temp_file, 'rb') as f:
            res = f.readline()
            self.assertEqual(expected_msg, res) 
開發者ID:openstack,項目名稱:networking-sfc,代碼行數:23,代碼來源:test_service.py

示例4: test_run_forwards_sighup

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def test_run_forwards_sighup(devnull):
    proc = subprocess.Popen([
            sys.executable, '-m', 'covimerage', 'run',
            '--no-write-data', '--no-wrap-profile',
            '--profile-file', devnull.name,
            sys.executable, '-c',
            'import signal, sys, time; '
            'signal.signal(signal.SIGHUP, lambda *args: sys.exit(89)); '
            'time.sleep(2)'],
                          stderr=subprocess.PIPE)
    time.sleep(1)
    proc.send_signal(signal.SIGHUP)
    _, stderr = proc.communicate()
    exit_code = proc.returncode

    stderr = stderr.decode()
    assert 'Command exited non-zero: 89' in stderr
    assert exit_code == 89 
開發者ID:Vimjas,項目名稱:covimerage,代碼行數:20,代碼來源:test_cli.py

示例5: initialize_signal_handlers

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def initialize_signal_handlers(self):
        def handle_sighup(signum, frame):
            logging.info("received SIGHUP")
            self.sighup_received = True

        def handle_sigterm(signal, frame):
            logging.info("received SIGTERM")
            self.sigterm_received = True

        def handle_sigint(signal, frame):
            logging.info("received SIGINT")
            self.sigint_received = True

        signal.signal(signal.SIGTERM, handle_sigterm)
        signal.signal(signal.SIGHUP, handle_sighup)
        signal.signal(signal.SIGINT, handle_sigint) 
開發者ID:IntegralDefense,項目名稱:ACE,代碼行數:18,代碼來源:__init__.py

示例6: hm_health_check

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def hm_health_check(exit_event):
    hm = health_manager.HealthManager(exit_event)
    signal.signal(signal.SIGHUP, _mutate_config)

    @periodics.periodic(CONF.health_manager.health_check_interval,
                        run_immediately=True)
    def periodic_health_check():
        hm.health_check()

    health_check = periodics.PeriodicWorker(
        [(periodic_health_check, None, None)],
        schedule_strategy='aligned_last_finished')

    def hm_exit(*args, **kwargs):
        health_check.stop()
        hm.executor.shutdown()
    signal.signal(signal.SIGINT, hm_exit)
    LOG.debug("Pausing before starting health check")
    exit_event.wait(CONF.health_manager.heartbeat_timeout)
    health_check.start() 
開發者ID:openstack,項目名稱:octavia,代碼行數:22,代碼來源:health_manager.py

示例7: _process_wrapper

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def _process_wrapper(exit_event, proc_name, function, agent_name=None):
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    signal.signal(signal.SIGHUP, _mutate_config)
    if agent_name:
        process_title = 'octavia-driver-agent - {} -- {}'.format(
            proc_name, agent_name)
    else:
        process_title = 'octavia-driver-agent - {}'.format(proc_name)
    setproctitle.setproctitle(process_title)
    while not exit_event.is_set():
        try:
            function(exit_event)
        except Exception as e:
            if agent_name:
                LOG.exception('Provider agent "%s" raised exception: %s. '
                              'Restarting the "%s" provider agent.',
                              agent_name, str(e), agent_name)
            else:
                LOG.exception('%s raised exception: %s. '
                              'Restarting %s.',
                              proc_name, str(e), proc_name)
            time.sleep(1)
            continue
        break 
開發者ID:openstack,項目名稱:octavia,代碼行數:26,代碼來源:driver_agent.py

示例8: close

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def close (self, force=True):   # File-like object.

        """This closes the connection with the child application. Note that
        calling close() more than once is valid. This emulates standard Python
        behavior with files. Set force to True if you want to make sure that
        the child is terminated (SIGKILL is sent if the child ignores SIGHUP
        and SIGINT). """

        if not self.closed:
            self.flush()
            os.close (self.child_fd)
            time.sleep(self.delayafterclose) # Give kernel time to update process status.
            if self.isalive():
                if not self.terminate(force):
                    raise ExceptionPexpect ('close() could not terminate the child using terminate()')
            self.child_fd = -1
            self.closed = True
            #self.pid = None 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:_pexpect.py

示例9: test_sighup

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def test_sighup(self):
        self.assert_everything_has_started()
        os.kill(self.subp.pid, signal.SIGHUP)
        time.sleep(0.5)
        lines = sorted(self.get_lines(6))
        lines = self.hide_pids(lines)
        self.assertEqual([
            b'DEBUG:cotyledon._service:Run service light(0) [XXXX]',
            b'ERROR:cotyledon.tests.examples:heavy reload',
            b'ERROR:cotyledon.tests.examples:heavy reload',
            b'ERROR:cotyledon.tests.examples:master reload hook',
            b'INFO:cotyledon._service:Caught SIGTERM signal, '
            b'graceful exiting of service light(0) [XXXX]',
            b'INFO:cotyledon._service_manager:Child XXXX exited with status 0'
        ], lines)

        os.kill(self.subp.pid, signal.SIGINT)
        time.sleep(0.5)
        self.assert_everything_is_dead(1) 
開發者ID:sileht,項目名稱:cotyledon,代碼行數:21,代碼來源:test_functional.py

示例10: __init__

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def __init__(self):
        # Setup signal fd, this allows signal to behave correctly
        if os.name == 'posix':
            self.signal_pipe_r, self.signal_pipe_w = os.pipe()
            self._set_nonblock(self.signal_pipe_r)
            self._set_nonblock(self.signal_pipe_w)
            signal.set_wakeup_fd(self.signal_pipe_w)

        self._signals_received = collections.deque()

        signal.signal(signal.SIGINT, signal.SIG_DFL)
        if os.name == 'posix':
            signal.signal(signal.SIGCHLD, signal.SIG_DFL)
            signal.signal(signal.SIGTERM, self._signal_catcher)
            signal.signal(signal.SIGALRM, self._signal_catcher)
            signal.signal(signal.SIGHUP, self._signal_catcher)
        else:
            # currently a noop on window...
            signal.signal(signal.SIGTERM, self._signal_catcher)
            # FIXME(sileht): should allow to catch signal CTRL_BREAK_EVENT,
            # but we to create the child process with CREATE_NEW_PROCESS_GROUP
            # to make this work, so current this is a noop for later fix
            signal.signal(signal.SIGBREAK, self._signal_catcher) 
開發者ID:sileht,項目名稱:cotyledon,代碼行數:25,代碼來源:_utils.py

示例11: close

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def close(self, force=True):
        '''This closes the connection with the child application. Note that
        calling close() more than once is valid. This emulates standard Python
        behavior with files. Set force to True if you want to make sure that
        the child is terminated (SIGKILL is sent if the child ignores SIGHUP
        and SIGINT). '''
        if not self.closed:
            self.flush()
            self.fileobj.close() # Closes the file descriptor
            # Give kernel time to update process status.
            time.sleep(self.delayafterclose)
            if self.isalive():
                if not self.terminate(force):
                    raise PtyProcessError('Could not terminate the child.')
            self.fd = -1
            self.closed = True
            #self.pid = None 
開發者ID:pypa,項目名稱:pipenv,代碼行數:19,代碼來源:ptyprocess.py

示例12: reload

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def reload():
    """
    Sends a SIGHUP to the running daemon to tell it to reload all modules.
    """
    log.info('reloading server.')

    try:
        pid = read_pid()
    except Exception as e:
        log.critical('could not read PID file: %s' % e)
        return

    try:
        os.kill(pid, signal.SIGHUP)
    except Exception as e:
        log.critical('could not reload server: %s' % e) 
開發者ID:pycepa,項目名稱:pycepa,代碼行數:18,代碼來源:daemon.py

示例13: register_signal_handlers

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def register_signal_handlers(callback):
    # When using plain signal.signal to install a signal handler, the GUI will not shutdown until it receives the
    # focus again. The following logic (inspired from https://stackoverflow.com/a/26457317) fixes this
    def install_glib_handler(sig):
        unix_signal_add = None

        if hasattr(GLib, "unix_signal_add"):
            unix_signal_add = GLib.unix_signal_add
        elif hasattr(GLib, "unix_signal_add_full"):
            unix_signal_add = GLib.unix_signal_add_full

        if unix_signal_add:
            unix_signal_add(GLib.PRIORITY_HIGH, sig, callback, sig)

    def idle_handler(*args):
        GLib.idle_add(callback, *args, priority=GLib.PRIORITY_HIGH)

    for signal_code in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]:
        signal.signal(signal_code, idle_handler)
        GLib.idle_add(install_glib_handler, signal_code, priority=GLib.PRIORITY_HIGH) 
開發者ID:DLR-RM,項目名稱:RAFCON,代碼行數:22,代碼來源:start.py

示例14: test_send_signal

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def test_send_signal(self):
        code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
        args = [sys.executable, '-c', code]
        create = asyncio.create_subprocess_exec(*args,
                                                stdout=subprocess.PIPE,
                                                loop=self.loop)
        proc = self.loop.run_until_complete(create)

        @asyncio.coroutine
        def send_signal(proc):
            # basic synchronization to wait until the program is sleeping
            line = yield from proc.stdout.readline()
            self.assertEqual(line, b'sleeping\n')

            proc.send_signal(signal.SIGHUP)
            returncode = (yield from proc.wait())
            return returncode

        returncode = self.loop.run_until_complete(send_signal(proc))
        self.assertEqual(-signal.SIGHUP, returncode) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:test_subprocess.py

示例15: _signal_handling

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGHUP [as 別名]
def _signal_handling(logger: logging.Logger, client: naz.Client) -> None:
    try:
        loop = asyncio.get_running_loop()
    except RuntimeError:
        loop = asyncio.get_event_loop()

    try:
        for _signal in [signal.SIGHUP, signal.SIGQUIT, signal.SIGTERM]:
            loop.add_signal_handler(
                _signal,
                functools.partial(
                    asyncio.ensure_future,
                    _handle_termination_signal(logger=logger, _signal=_signal, client=client),
                ),
            )
    except ValueError as e:
        logger.log(
            logging.DEBUG,
            {
                "event": "naz.cli.signals",
                "stage": "end",
                "state": "this OS does not support the said signal",
                "error": str(e),
            },
        ) 
開發者ID:komuw,項目名稱:naz,代碼行數:27,代碼來源:sig.py


注:本文中的signal.SIGHUP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。