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


Python signal.default_int_handler方法代码示例

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


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

示例1: __init__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def __init__(self, default_handler):
        self.called = False
        self.original_handler = default_handler
        if isinstance(default_handler, int):
            if default_handler == signal.SIG_DFL:
                # Pretend it's signal.default_int_handler instead.
                default_handler = signal.default_int_handler
            elif default_handler == signal.SIG_IGN:
                # Not quite the same thing as SIG_IGN, but the closest we
                # can make it: do nothing.
                def default_handler(unused_signum, unused_frame):
                    pass
            else:
                raise TypeError("expected SIGINT signal handler to be "
                                "signal.SIG_IGN, signal.SIG_DFL, or a "
                                "callable object")
        self.default_handler = default_handler 
开发者ID:war-and-code,项目名称:jawfish,代码行数:19,代码来源:signals.py

示例2: _shutdown_on_exception

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def _shutdown_on_exception(app: skein.ApplicationClient):
    # Ensure SIGINT is not masked to enable kill on C-c.
    import signal
    signal.signal(signal.SIGINT, signal.default_int_handler)

    try:
        yield
    except (KeyboardInterrupt, SystemExit):
        with suppress(SkeinError):
            app.shutdown(FinalStatus.KILLED)
        logger.error("Application killed on user request")
    except Exception:
        with suppress(SkeinError):
            app.shutdown(FinalStatus.FAILED)
        logger.exception("Application shutdown due to an exception")
        raise 
开发者ID:criteo,项目名称:tf-yarn,代码行数:18,代码来源:client.py

示例3: _downloadLocalFile

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def _downloadLocalFile(self, key, suffix):
        # Set default signal handler so that KeyboardInterrupt is raised.
        # Needed to gracefully handle ctrl+c.
        signal.signal(signal.SIGINT, signal.default_int_handler)

        try:
            with self._openDownloadFile(key, suffix) as (name, fileobj):
                ret = readFileOrHandle(name, fileobj)
            return (ret, None, None)
        except ArtifactNotFoundError:
            return (None, "not found", WARNING)
        except ArtifactDownloadError as e:
            return (None, e.reason, WARNING)
        except BuildError as e:
            raise
        except OSError as e:
            raise BuildError("Cannot download file: " + str(e))
        finally:
            # Restore signals to default so that Ctrl+C kills process. Needed
            # to prevent ugly backtraces when user presses ctrl+c.
            signal.signal(signal.SIGINT, signal.SIG_DFL) 
开发者ID:BobBuildTool,项目名称:bob,代码行数:23,代码来源:archive.py

示例4: _uploadPackage

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def _uploadPackage(self, buildId, suffix, audit, content):
        # Set default signal handler so that KeyboardInterrupt is raised.
        # Needed to gracefully handle ctrl+c.
        signal.signal(signal.SIGINT, signal.default_int_handler)

        try:
            with self._openUploadFile(buildId, suffix) as (name, fileobj):
                pax = { 'bob-archive-vsn' : "1" }
                with gzip.open(name or fileobj, 'wb', 6) as gzf:
                    with tarfile.open(name, "w", fileobj=gzf,
                                      format=tarfile.PAX_FORMAT, pax_headers=pax) as tar:
                        tar.add(audit, "meta/" + os.path.basename(audit))
                        tar.add(content, arcname="content")
        except ArtifactExistsError:
            return ("skipped ({} exists in archive)".format(content), SKIPPED)
        except (ArtifactUploadError, tarfile.TarError, OSError) as e:
            if self.__ignoreErrors:
                return ("error ("+str(e)+")", ERROR)
            else:
                raise BuildError("Cannot upload artifact: " + str(e))
        finally:
            # Restore signals to default so that Ctrl+C kills process. Needed
            # to prevent ugly backtraces when user presses ctrl+c.
            signal.signal(signal.SIGINT, signal.SIG_DFL)
        return ("ok", EXECUTED) 
开发者ID:BobBuildTool,项目名称:bob,代码行数:27,代码来源:archive.py

示例5: _uploadLocalFile

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def _uploadLocalFile(self, key, suffix, content):
        # Set default signal handler so that KeyboardInterrupt is raised.
        # Needed to gracefully handle ctrl+c.
        signal.signal(signal.SIGINT, signal.default_int_handler)

        try:
            with self._openUploadFile(key, suffix) as (name, fileobj):
                writeFileOrHandle(name, fileobj, content)
        except ArtifactExistsError:
            return ("skipped (exists in archive)", SKIPPED)
        except (ArtifactUploadError, OSError) as e:
            if self.__ignoreErrors:
                return ("error ("+str(e)+")", ERROR)
            else:
                raise BuildError("Cannot upload file: " + str(e))
        finally:
            # Restore signals to default so that Ctrl+C kills process. Needed
            # to prevent ugly backtraces when user presses ctrl+c.
            signal.signal(signal.SIGINT, signal.SIG_DFL)
        return ("ok", EXECUTED) 
开发者ID:BobBuildTool,项目名称:bob,代码行数:22,代码来源:archive.py

示例6: __init__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def __init__(self, default_handler):
        self.called = False
        self.original_handler = default_handler
        if isinstance(default_handler, (int, long)):
            if default_handler == signal.SIG_DFL:
                # Pretend it's signal.default_int_handler instead.
                default_handler = signal.default_int_handler
            elif default_handler == signal.SIG_IGN:
                # Not quite the same thing as SIG_IGN, but the closest we
                # can make it: do nothing.
                def default_handler(unused_signum, unused_frame):
                    pass
            else:
                raise TypeError("expected SIGINT signal handler to be "
                                "signal.SIG_IGN, signal.SIG_DFL, or a "
                                "callable object")
        self.default_handler = default_handler 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:signals.py

示例7: MakeValidSysOuts

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def MakeValidSysOuts():
	if not isinstance(sys.stdout, SafeOutput):
		sys.stdout = sys.stderr = SafeOutput()
		# and for the sake of working around something I can't understand...
		# prevent keyboard interrupts from killing IIS
		import signal
		def noOp(a,b):
			# it would be nice to get to the bottom of this, so a warning to
			# the debug console can't hurt.
			print "WARNING: Ignoring keyboard interrupt from ActiveScripting engine"
		# If someone else has already redirected, then assume they know what they are doing!
		if signal.getsignal(signal.SIGINT) == signal.default_int_handler:
			try:
				signal.signal(signal.SIGINT, noOp)
			except ValueError:
				# Not the main thread - can't do much.
				pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:framework.py

示例8: test_signal_signal

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def test_signal_signal(self):
        WORKING_CASES = SUPPORTED_SIGNALS + [6]
        WEIRD_CASES = {
                    6: None,
                    2: signal.default_int_handler}
        for x in WORKING_CASES:
            #Ideal handler signature
            def a(signum, frame):
                return x
            
            ret_val = signal.signal(x, a)
            if x not in WEIRD_CASES.keys():
                self.assertEqual(ret_val, signal.SIG_DFL)
            else:
                self.assertEqual(ret_val, WEIRD_CASES[x])
            self.assertEqual(a, signal.getsignal(x))
            
        #Strange handler signatures
        class KNew(object):
            def __call__(self, *args, **kwargs):
                pass
        
        a = KNew()
        ret_val = signal.signal(signal.SIGBREAK, a)
        self.assertEqual(a, signal.getsignal(signal.SIGBREAK)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_signal.py

示例9: _handleSignals

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def _handleSignals(self):
        """
        Install the signal handlers for the Twisted event loop.
        """
        try:
            import signal
        except ImportError:
            log.msg("Warning: signal module unavailable -- "
                    "not installing signal handlers.")
            return

        if signal.getsignal(signal.SIGINT) == signal.default_int_handler:
            # only handle if there isn't already a handler, e.g. for Pdb.
            signal.signal(signal.SIGINT, self.sigInt)
        signal.signal(signal.SIGTERM, self.sigTerm)

        # Catch Ctrl-Break in windows
        if hasattr(signal, "SIGBREAK"):
            signal.signal(signal.SIGBREAK, self.sigBreak) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:base.py

示例10: handle_error

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def handle_error(index_name, keep=False, timeout=None):
    '''
    Handle errors while indexing.
    In case of error, properly log it, remove the index and exit.
    If `keep` is `True`, index is not deleted.
    '''
    # Handle keyboard interrupt
    signal.signal(signal.SIGINT, signal.default_int_handler)
    signal.signal(signal.SIGTERM, signal.default_int_handler)
    has_error = False
    try:
        yield
    except KeyboardInterrupt:
        print('')  # Proper warning message under the "^C" display
        log.warning('Interrupted by signal')
        has_error = True
    except Exception as e:
        log.error(e)
        has_error = True
    if has_error:
        if not keep:
            log.info('Removing index %s', index_name)
            es.indices.delete(index=index_name, request_timeout=timeout)
        sys.exit(-1) 
开发者ID:opendatateam,项目名称:udata,代码行数:26,代码来源:commands.py

示例11: handle_error

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def handle_error(prefix, to_delete=None):
    '''
    Handle errors while loading.
    In case of error, properly log it, remove the temporary files and collections and exit.
    If `to_delete` is given a collection, it will be deleted deleted.
    '''
    # Handle keyboard interrupt
    signal.signal(signal.SIGINT, signal.default_int_handler)
    signal.signal(signal.SIGTERM, signal.default_int_handler)
    try:
        yield
    except KeyboardInterrupt:
        print('')  # Proper warning message under the "^C" display
        log.warning('Interrupted by signal')
    except Exception as e:
        log.error(e)
    else:
        return  # Nothing to do in case of success
    cleanup(prefix)
    if to_delete:
        log.info('Removing temporary collection %s', to_delete._get_collection_name())
        to_delete.drop_collection()
    sys.exit(-1) 
开发者ID:opendatateam,项目名称:udata,代码行数:25,代码来源:commands.py

示例12: _kill_process

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def _kill_process(self, method, *args):
        # Do not inherit file handles from the parent.
        # It should fix failures on some platforms.
        # Also set the SIGINT handler to the default to make sure it's not
        # being ignored (some tests rely on that.)
        old_handler = signal.signal(signal.SIGINT, signal.default_int_handler)
        try:
            p = subprocess.Popen([sys.executable, "-c", """if 1:
                                 import sys, time
                                 sys.stdout.write('x\\n')
                                 sys.stdout.flush()
                                 time.sleep(30)
                                 """],
                                 close_fds=True,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        finally:
            signal.signal(signal.SIGINT, old_handler)
        # Wait for the interpreter to be completely initialized before
        # sending any signal.
        p.stdout.read(1)
        getattr(p, method)(*args)
        return p 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_subprocess.py

示例13: _run

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def _run(self) -> None:
        signal.signal(signal.SIGINT, signal.default_int_handler)
        signal.signal(signal.SIGTERM, signal.default_int_handler)

        try:
            self.log.debug("Running startup actions...")
            start_ts = time()
            self.loop.run_until_complete(self.start())
            end_ts = time()
            self.log.info(f"Startup actions complete in {round(end_ts - start_ts, 2)} seconds, "
                           "now running forever")
            self._stop_task = self.loop.create_future()
            self.loop.run_until_complete(self._stop_task)
            self.log.debug("manual_stop() called, stopping...")
        except KeyboardInterrupt:
            self.log.debug("Interrupt received, stopping...")
        except Exception:
            self.log.critical("Unexpected error in main event loop", exc_info=True)
            sys.exit(2)
        self.prepare_stop()
        self.loop.run_until_complete(self.stop())
        self.prepare_shutdown()
        self.log.info("Everything stopped, shutting down")
        sys.exit(0) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:26,代码来源:program.py

示例14: test_signal_signal

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def test_signal_signal(self):
        WORKING_CASES = SUPPORTED_SIGNALS + [6]
        WEIRD_CASES = {
                    6: None,
                    2: signal.default_int_handler}
        for x in WORKING_CASES:
            #Ideal handler signature
            def a(signum, frame):
                return x

            ret_val = signal.signal(x, a)
            if x not in WEIRD_CASES.keys():
                self.assertEqual(ret_val, signal.SIG_DFL)
            else:
                self.assertEqual(ret_val, WEIRD_CASES[x])
            self.assertEqual(a, signal.getsignal(x))

        #Strange handler signatures
        class KNew(object):
            def __call__(self, *args, **kwargs):
                pass

        a = KNew()
        ret_val = signal.signal(signal.SIGBREAK, a)
        self.assertEqual(a, signal.getsignal(signal.SIGBREAK)) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test_signal.py

示例15: waitForInterrupt

# 需要导入模块: import signal [as 别名]
# 或者: from signal import default_int_handler [as 别名]
def waitForInterrupt():
    if signal.getsignal(signal.SIGINT) != signal.default_int_handler:
        raise RuntimeError("Already waiting")

    d = Deferred()

    def fire(*ignored):
        global interrupted
        signal.signal(signal.SIGINT, signal.default_int_handler)
        now = time.time()
        if now - interrupted < 4:
            reactor.callFromThread(lambda: d.errback(Failure(Stop())))
        else:
            interrupted = now
            reactor.callFromThread(d.callback, None)
    signal.signal(signal.SIGINT, fire)
    return d 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:19,代码来源:sqlwatch.py


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