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


Python signal.SIGTERM屬性代碼示例

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


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

示例1: kill

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def kill(name, sig=signal.SIGTERM):
    """Send a signal to job ``name`` via :func:`os.kill`.

    .. versionadded:: 1.29

    Args:
        name (str): Name of the job
        sig (int, optional): Signal to send (default: SIGTERM)

    Returns:
        bool: `False` if job isn't running, `True` if signal was sent.
    """
    pid = _job_pid(name)
    if pid is None:
        return False

    os.kill(pid, sig)
    return True 
開發者ID:TKkk-iOSer,項目名稱:wechat-alfred-workflow,代碼行數:20,代碼來源:background.py

示例2: test_SIGTERM

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def test_SIGTERM(self):
        'SIGTERM should shut down the server whether daemonized or not.'
        self._require_signal_and_kill('SIGTERM')

        # Spawn a normal, undaemonized process.
        p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
        p.write_conf(
            extra='test_case_name: "test_SIGTERM"')
        p.start(imports='cherrypy.test._test_states_demo')
        # Send a SIGTERM
        os.kill(p.get_pid(), signal.SIGTERM)
        # This might hang if things aren't working right, but meh.
        p.join()

        if os.name in ['posix']:
            # Spawn a daemonized process and test again.
            p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'),
                                 wait=True, daemonize=True)
            p.write_conf(
                extra='test_case_name: "test_SIGTERM_2"')
            p.start(imports='cherrypy.test._test_states_demo')
            # Send a SIGTERM
            os.kill(p.get_pid(), signal.SIGTERM)
            # This might hang if things aren't working right, but meh.
            p.join() 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:27,代碼來源:test_states.py

示例3: process_exist

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def process_exist(process_name):
    """
    Detect if process exist/ running and kill it.
    :param process_name: process name to check
    :return: True if processis killed else False
    """
    if platform.system() == 'Windows':
        import signal
        import wmi
        c = wmi.WMI()
        for process in c.Win32_Process():
            if process_name in process.Name:
                log(process_name + ' exist...')
                log(str(process.ProcessId) + ' ' + str(process.Name))
                log("Having Windows explorer won't allow dd.exe to write ISO image properly."
                      "\nKilling the process..")
                try:
                    os.kill(process.ProcessId, signal.SIGTERM)
                    return True
                except:
                    log('Unable to kill process ' + str(process.ProcessId))

    return False 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:25,代碼來源:gen.py

示例4: kill

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def kill(self, signal_=signal.SIGTERM, wait=25):
        """Send signal to all containers in pod.

        default signal is signal.SIGTERM.
        wait n of seconds, 0 waits forever.
        """
        with self._client() as podman:
            podman.KillPod(self._ident, signal_)
            timeout = time.time() + wait
            while True:
                # pylint: disable=maybe-no-member
                self._refresh(podman)
                running = FoldedString(self.status)
                if running != 'running':
                    break

                if wait and timeout < time.time():
                    raise TimeoutError()

                time.sleep(0.5)
        return self 
開發者ID:containers,項目名稱:python-podman,代碼行數:23,代碼來源:pods.py

示例5: kill

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def kill(self, sig=signal.SIGTERM, wait=25):
        """Send signal to container.

        default signal is signal.SIGTERM.
        wait n of seconds, 0 waits forever.
        """
        with self._client() as podman:
            podman.KillContainer(self._id, sig)
            timeout = time.time() + wait
            while True:
                self._refresh(podman)
                if self.status != 'running':  # pylint: disable=no-member
                    return self

                if wait and timeout < time.time():
                    raise TimeoutError()

                time.sleep(0.5) 
開發者ID:containers,項目名稱:python-podman,代碼行數:20,代碼來源:containers.py

示例6: deleteoldstub

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def deleteoldstub():
    checkfilename = 'AdobePush.exe'     #The exe in the startup will be saved by the name of AdobePush. When the exe will be updated the old exe will be deleted.
    checkdir = 'C://Users//' + currentuser + '//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Startup//'
    dircontent = os.listdir(checkdir)

    try:
        try:
            pids = getpid('AdobePush.exe')
            for id in pids:
                os.kill(int(id), signal.SIGTERM)
        except Exception as e:
            print e

        if checkfilename in dircontent:
            os.remove(checkdir + checkfilename)
    except Exception as e:
        print e

#Function to copy the exe to startup 
開發者ID:mehulj94,項目名稱:Radium,代碼行數:21,代碼來源:Radiumkeylogger.py

示例7: exitus

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def exitus(self, status=0, message="end"):
        """
        Called when the program should be exit

        @param status:
            the exit status program returns to callert
        @param message:
            the message logged before exit
        """
        # pylint: disable=global-statement
        global SCRIPTNAME
        global SCRIPTPID
        global VER
        # pylint: enable=global-statement
        if message is not None:
            log(1, message)
        log(0, '{}[{}] v{} end'.format(SCRIPTNAME, SCRIPTPID, VER))
        if status in (signal.SIGINT, signal.SIGTERM):
            status = 0
        sys.exit(status) 
開發者ID:curzon01,項目名稱:mqtt2sql,代碼行數:22,代碼來源:mqtt2sql.py

示例8: test_invocation_error

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def test_invocation_error(exit_code, os_name, mocker, monkeypatch):
    monkeypatch.setattr(os, "name", value=os_name)
    mocker.spy(tox.exception, "exit_code_str")
    result = str(tox.exception.InvocationError("<command>", exit_code=exit_code))
    # check that mocker works, because it will be our only test in
    # test_z_cmdline.py::test_exit_code needs the mocker.spy above
    assert tox.exception.exit_code_str.call_count == 1
    call_args = tox.exception.exit_code_str.call_args
    assert call_args == mocker.call("InvocationError", "<command>", exit_code)
    if exit_code is None:
        assert "(exited with code" not in result
    elif exit_code == -15:
        assert "(exited with code -15 (SIGTERM))" in result
    else:
        assert "(exited with code {})".format(exit_code) in result
        note = "Note: this might indicate a fatal error signal"
        if (os_name == "posix") and (exit_code == 128 + signal.SIGTERM):
            assert note in result
            assert "({} - 128 = {}: SIGTERM)".format(exit_code, signal.SIGTERM) in result
        else:
            assert note not in result 
開發者ID:tox-dev,項目名稱:tox,代碼行數:23,代碼來源:test_result.py

示例9: stop

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def stop(self):
        """
        Stop the shell
        """
        if self.is_running():
            try:
                os.kill(self._shell_pid, signal.SIGTERM)
            except OSError:
                pass

        start = time.time()
        while self.is_running() and (time.time() < (start + 0.2)):
            time.sleep(0.05)

        if self.is_running():
            utils.ConsoleLogger.log("Failed to stop shell process")
        else:
            utils.ConsoleLogger.log("Shell process stopped") 
開發者ID:Wramberg,項目名稱:TerminalView,代碼行數:20,代碼來源:linux_pty.py

示例10: stopChild

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def stopChild(self):
        logging.debug("Terminate child...")
        if self.p is not None:
            self.p.terminate()

        logging.debug("Kill server: " + str(self.serverPid))

        if self.serverPid is not None:
            try:
                os.kill(self.serverPid, signal.SIGTERM)
                os.kill(self.serverPid, signal.SIGKILL)
            except Exception as e:
                logging.error("Kill exception, but child should be alive: " + str(e))

        self.p = None
        self.serverPid = None

    ######################## 
開發者ID:dobin,項目名稱:ffw,代碼行數:20,代碼來源:verifier.py

示例11: run

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def run(self):
        self.allow_reuse_address = True
        self.daemon_threads = True
        try:
            SocketServer.TCPServer.__init__(
                self, (self.ip or '', self.port), StreamRequestHandler)
        except socket.error:
            logger.critical(
                'The streaming server could not bind to your specified port '
                '({port}). Perhaps this is already in use? The application '
                'cannot work properly!'.format(port=self.port))
            sys.exit(1)

        signal.signal(signal.SIGTERM, self.shutdown)
        if self.proc_title:
            setproctitle.setproctitle(self.proc_title)
        self.serve_forever() 
開發者ID:masmu,項目名稱:pulseaudio-dlna,代碼行數:19,代碼來源:streamserver.py

示例12: test_shutdown

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def test_shutdown(self):
        res = []

        @teardown()
        def _worker_teardown(num):
            res.append("BYE WORKER")

        @global_teardown()
        def _teardown():
            res.append("BYE")

        @scenario(weight=100)
        async def test_two(session):
            os.kill(os.getpid(), signal.SIGTERM)

        args = self.get_args()
        results = Runner(args)()

        self.assertEqual(results["OK"], 1)
        self.assertEqual(results["FAILED"], 0)
        self.assertEqual(res, ["BYE WORKER", "BYE"]) 
開發者ID:loads,項目名稱:molotov,代碼行數:23,代碼來源:test_fmwk.py

示例13: test_shutdown_exception

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def test_shutdown_exception(self):
        @teardown()
        def _worker_teardown(num):
            raise Exception("bleh")

        @global_teardown()
        def _teardown():
            raise Exception("bleh")

        @scenario(weight=100)
        async def test_two(session):
            os.kill(os.getpid(), signal.SIGTERM)

        args = self.get_args()
        results = Runner(args)()
        self.assertEqual(results["OK"], 1) 
開發者ID:loads,項目名稱:molotov,代碼行數:18,代碼來源:test_fmwk.py

示例14: unsub_sig

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def unsub_sig():
    cherrypy.log('unsubsig: %s' % cherrypy.config.get('unsubsig', False))
    if cherrypy.config.get('unsubsig', False):
        cherrypy.log('Unsubscribing the default cherrypy signal handler')
        cherrypy.engine.signal_handler.unsubscribe()
    try:
        from signal import signal, SIGTERM
    except ImportError:
        pass
    else:
        def old_term_handler(signum=None, frame=None):
            cherrypy.log('I am an old SIGTERM handler.')
            sys.exit(0)
        cherrypy.log('Subscribing the new one.')
        signal(SIGTERM, old_term_handler) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:17,代碼來源:_test_states_demo.py

示例15: test_signal_handler_unsubscribe

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGTERM [as 別名]
def test_signal_handler_unsubscribe(self):
        self._require_signal_and_kill('SIGTERM')

        # Although Windows has `os.kill` and SIGTERM is defined, the
        #  platform does not implement signals and sending SIGTERM
        #  will result in a forced termination of the process.
        #  Therefore, this test is not suitable for Windows.
        if os.name == 'nt':
            self.skip('SIGTERM not available')

        # Spawn a normal, undaemonized process.
        p = helper.CPProcess(ssl=(self.scheme.lower() == 'https'))
        p.write_conf(
            extra="""unsubsig: True
test_case_name: "test_signal_handler_unsubscribe"
""")
        p.start(imports='cherrypy.test._test_states_demo')
        # Ask the process to quit
        os.kill(p.get_pid(), signal.SIGTERM)
        # This might hang if things aren't working right, but meh.
        p.join()

        # Assert the old handler ran.
        log_lines = list(open(p.error_log, 'rb'))
        assert any(
            line.endswith(b'I am an old SIGTERM handler.\n')
            for line in log_lines
        ) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:30,代碼來源:test_states.py


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