本文整理汇总了Python中signal.SIG_DFL属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIG_DFL属性的具体用法?Python signal.SIG_DFL怎么用?Python signal.SIG_DFL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIG_DFL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def __call__(self, *args, **kwargs):
"""Trap ``SIGTERM`` and call wrapped function."""
self._caught_signal = None
# Register handler for SIGTERM, then call `self.func`
self.old_signal_handler = signal.getsignal(signal.SIGTERM)
signal.signal(signal.SIGTERM, self.signal_handler)
self.func(*args, **kwargs)
# Restore old signal handler
signal.signal(signal.SIGTERM, self.old_signal_handler)
# Handle any signal caught during execution
if self._caught_signal is not None:
signum, frame = self._caught_signal
if callable(self.old_signal_handler):
self.old_signal_handler(signum, frame)
elif self.old_signal_handler == signal.SIG_DFL:
sys.exit(0)
示例2: unsubscribe
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def unsubscribe(self):
"""Unsubscribe self.handlers from signals."""
for signum, handler in self._previous_handlers.items():
signame = self.signals[signum]
if handler is None:
self.bus.log('Restoring %s handler to SIG_DFL.' % signame)
handler = _signal.SIG_DFL
else:
self.bus.log('Restoring %s handler %r.' % (signame, handler))
try:
our_handler = _signal.signal(signum, handler)
if our_handler is None:
self.bus.log('Restored old %s handler %r, but our '
'handler was not registered.' %
(signame, handler), level=30)
except ValueError:
self.bus.log('Unable to restore %s handler %r.' %
(signame, handler), level=40, traceback=True)
示例3: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [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
示例4: closeConnections
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def closeConnections(self):
try:
self.workerSocket.shutdown(socket.SHUT_RDWR)
except:
pass
try:
self.workerSocket.close()
except:
pass
try:
self.clientSocket.shutdown(socket.SHUT_RDWR)
except:
pass
try:
self.clientSocket.close()
except:
pass
signal.signal(signal.SIGTERM, signal.SIG_DFL)
示例5: __call__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def __call__(self, *args, **kwargs):
self._caught_signal = None
# Register handler for SIGTERM, then call `self.func`
self.old_signal_handler = signal.getsignal(signal.SIGTERM)
signal.signal(signal.SIGTERM, self.signal_handler)
self.func(*args, **kwargs)
# Restore old signal handler
signal.signal(signal.SIGTERM, self.old_signal_handler)
# Handle any signal caught during execution
if self._caught_signal is not None:
signum, frame = self._caught_signal
if callable(self.old_signal_handler):
self.old_signal_handler(signum, frame)
elif self.old_signal_handler == signal.SIG_DFL:
sys.exit(0)
示例6: context
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def context(**handlers):
signals = {}
def handler(signum, frame):
signame = SIGNAL_NAMES[signum]
signals[signame] = True
handler = handlers[signame]
handler()
def set_all(handler):
for signame in handlers:
if signame in SIGNAL_NUMBERS: # Windows doesn't have all signals
signal.signal(SIGNAL_NUMBERS[signame], handler)
set_all(handler)
try:
yield signals
finally:
set_all(signal.SIG_DFL)
示例7: _downloadLocalFile
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [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)
示例8: _uploadPackage
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [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)
示例9: _uploadLocalFile
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [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)
示例10: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [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
示例11: test_signal_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [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))
示例12: run
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def run(self):
"""
Run guest main thread
"""
global virt
global exiting
virt = VirtioGuestPosix()
slave = Thread(target=worker, args=(virt,))
slave.start()
signal.signal(signal.SIGUSR1, sigusr_handler)
signal.signal(signal.SIGALRM, sigusr_handler)
while not exiting:
signal.alarm(1)
signal.pause()
catch = virt.catching_signal()
if catch:
signal.signal(signal.SIGIO, virt)
elif catch is False:
signal.signal(signal.SIGIO, signal.SIG_DFL)
if catch is not None:
virt.use_config.set()
print("PASS: guest_exit")
sys.exit(0)
示例13: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [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)
示例14: installHandler
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def installHandler(fd):
"""
Install a signal handler which will write a byte to C{fd} when
I{SIGCHLD} is received.
This is implemented by installing a SIGCHLD handler that does nothing,
setting the I{SIGCHLD} handler as not allowed to interrupt system calls,
and using L{signal.set_wakeup_fd} to do the actual writing.
@param fd: The file descriptor to which to write when I{SIGCHLD} is
received.
@type fd: C{int}
"""
if fd == -1:
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
else:
def noopSignalHandler(*args):
pass
signal.signal(signal.SIGCHLD, noopSignalHandler)
signal.siginterrupt(signal.SIGCHLD, False)
return signal.set_wakeup_fd(fd)
示例15: setUp
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_DFL [as 别名]
def setUp(self):
"""
Save the current SIGCHLD handler as reported by L{signal.signal} and
the current file descriptor registered with L{installHandler}.
"""
handler = signal.getsignal(signal.SIGCHLD)
if handler != signal.SIG_DFL:
self.signalModuleHandler = handler
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
else:
self.signalModuleHandler = None
self.oldFD = installHandler(-1)
if self.signalModuleHandler is not None and self.oldFD != -1:
msg("Previous test didn't clean up after its SIGCHLD setup: %r %r"
% (self.signalModuleHandler, self.oldFD))