本文整理匯總了Python中signal.siginterrupt方法的典型用法代碼示例。如果您正苦於以下問題:Python signal.siginterrupt方法的具體用法?Python signal.siginterrupt怎麽用?Python signal.siginterrupt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類signal
的用法示例。
在下文中一共展示了signal.siginterrupt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: installHandler
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [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)
示例2: clone
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def clone(self, proc=None):
"""clone([proc]) clones the supplied process object and manages it as
well. If no process object is supplied then clone the first managed
process found in this ProcManager.
"""
if proc is None: # default to cloning first process found.
procs = self._procs.values()
if procs:
proc = procs[0]
del procs
else:
return
signal.signal(SIGCHLD, SIG_DFL) # critical area
newproc = proc.clone()
self._procs[newproc.childpid] = newproc
signal.signal(SIGCHLD, self._child_handler)
signal.siginterrupt(SIGCHLD, False)
return newproc
示例3: start
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def start(self):
self.last_profile_time = timer()
if self.use_signal:
try:
signal.signal(signal.SIGALRM, self._signal)
# the following tells the system to restart interrupted system calls if they are
# interrupted before any data has been transferred. This avoids many of the problems
# related to signals interrupting system calls, see issue #16
signal.siginterrupt(signal.SIGALRM, False)
except ValueError:
raise NotMainThreadError()
signal.setitimer(signal.ITIMER_REAL, self.interval, 0.0)
else:
sys.setprofile(self._profile)
示例4: init_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def init_signals(self) -> None:
# Set up signals through the event loop API.
self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,
signal.SIGQUIT, None)
self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,
signal.SIGTERM, None)
self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,
signal.SIGINT, None)
self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,
signal.SIGWINCH, None)
self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,
signal.SIGUSR1, None)
self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,
signal.SIGABRT, None)
# Don't let SIGTERM and SIGUSR1 disturb active requests
# by interrupting system calls
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
示例5: init_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def init_signals(self):
# reset signaling
[signal.signal(s, signal.SIG_DFL) for s in self.SIGNALS]
# init new signaling
signal.signal(signal.SIGQUIT, self.handle_quit)
signal.signal(signal.SIGTERM, self.handle_exit)
signal.signal(signal.SIGINT, self.handle_quit)
signal.signal(signal.SIGWINCH, self.handle_winch)
signal.signal(signal.SIGUSR1, self.handle_usr1)
signal.signal(signal.SIGABRT, self.handle_abort)
# Don't let SIGTERM and SIGUSR1 disturb active requests
# by interrupting system calls
if hasattr(signal, 'siginterrupt'): # python >= 2.6
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
示例6: stop
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def stop(self, signum=None, frame=None):
self.__tmpLog.info('Rank %s: stop signal %s received' % (self.__rank, signum))
self.__stop = True
block_sig(signum)
signal.siginterrupt(signum, False)
if self.__esJobManager:
self.__esJobManager.terminate()
self.getAccountingMetrics()
self.dumpJobMetrics()
self.heartbeat()
#self.__esJobManager.terminate()
self.__esJobManager.flushMessages()
self.updateOutputs(signal=True, final=True)
self.__tmpLog.info("Rank %s: post exec job" % self.__rank)
self.postExecJob()
#self.__tmpLog.info("Rank %s: finish job" % self.__rank)
#self.finishJob()
self.__tmpLog.info('Rank %s: stop' % self.__rank)
#signal.siginterrupt(signum, True)
unblock_sig(signum)
#sys.exit(0)
示例7: stop
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def stop(self, signum=None, frame=None):
self.tmpLog.info('stop signal %s received' % signum)
block_sig(signum)
signal.siginterrupt(signum, False)
self.dumpJobMetrics()
for jobId in self.jobsTimestamp:
if self.jobsTimestamp[jobId]['endTime'] is None:
self.jobsTimestamp[jobId]['endTime'] = time.time()
if len(self.jobsRuningRanks[jobId]) > 0:
self.jobsTimestamp[jobId]['endTime'] = time.time()
self.dumpJobsStartTime()
#self.flushMessages()
#self.updateFailedEventRanges()
# final dump
self.tmpLog.info('final dumping')
self.updateEventRangesToDB(force=True, final=True)
#self.db.dumpUpdates(True)
self.tmpLog.info("post Exec job")
self.postExecJob()
self.tmpLog.info('stop')
#signal.siginterrupt(signum, True)
unblock_sig(signum)
示例8: _installHandlerUsingSetWakeup
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def _installHandlerUsingSetWakeup(fd):
"""
Install a signal handler which will write a byte to C{fd} when
I{SIGCHLD} is received.
This is implemented by installing an instance of L{_Handler} wrapped
around C{None}, 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:
signal.signal(signal.SIGCHLD, _Handler(None))
siginterrupt(signal.SIGCHLD, False)
return set_wakeup_fd(fd)
示例9: handle_unix_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def handle_unix_signals(self):
if iswindows:
# TODO: test this on windows
self.signal_read_socket, self.signal_write_socket = socket.socketpair()
self.signal_read_socket.setblocking(False)
self.signal_write_socket.setblocking(False)
read_fd, write_fd = self.signal_read_socket.fileno(), self.signal_write_socket.fileno()
else:
read_fd, write_fd = pipe2()
for sig in (signal.SIGINT, signal.SIGTERM):
signal.signal(sig, lambda x, y: None)
signal.siginterrupt(sig, False)
signal.set_wakeup_fd(write_fd)
self.signal_notifier = QSocketNotifier(read_fd, QSocketNotifier.Read, self)
self.signal_notifier.setEnabled(True)
self.signal_notifier.activated.connect(self.signal_received, type=Qt.QueuedConnection)
示例10: command
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def command(self):
setproctitle('taskd')
self.basic_setup()
self.keep_running = True
self.restart_when_done = False
base.log.info('Starting taskd, pid %s' % os.getpid())
signal.signal(signal.SIGHUP, self.graceful_restart)
signal.signal(signal.SIGTERM, self.graceful_stop)
signal.signal(signal.SIGUSR1, self.log_current_task)
# restore default behavior of not interrupting system calls
# see http://docs.python.org/library/signal.html#signal.siginterrupt
# and http://linux.die.net/man/3/siginterrupt
signal.siginterrupt(signal.SIGHUP, False)
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
self.worker()
示例11: init_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def init_signals(self):
# Set up signals through the event loop API.
self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,
signal.SIGQUIT, None)
self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,
signal.SIGTERM, None)
self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,
signal.SIGINT, None)
self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,
signal.SIGWINCH, None)
self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,
signal.SIGUSR1, None)
self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,
signal.SIGABRT, None)
# Don't let SIGTERM and SIGUSR1 disturb active requests
# by interrupting system calls
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
示例12: init_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def init_signals(self):
# Set up signals through the event loop API.
self.loop.add_signal_handler(
signal.SIGQUIT, self.handle_quit, signal.SIGQUIT, None
)
self.loop.add_signal_handler(
signal.SIGTERM, self.handle_exit, signal.SIGTERM, None
)
self.loop.add_signal_handler(
signal.SIGINT, self.handle_quit, signal.SIGINT, None
)
self.loop.add_signal_handler(
signal.SIGWINCH, self.handle_winch, signal.SIGWINCH, None
)
self.loop.add_signal_handler(
signal.SIGUSR1, self.handle_usr1, signal.SIGUSR1, None
)
self.loop.add_signal_handler(
signal.SIGABRT, self.handle_abort, signal.SIGABRT, None
)
# Don't let SIGTERM and SIGUSR1 disturb active requests
# by interrupting system calls
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
示例13: init_signals
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def init_signals(self):
# reset signaling
[signal.signal(s, signal.SIG_DFL) for s in self.SIGNALS]
# init new signaling
signal.signal(signal.SIGQUIT, self.handle_quit)
signal.signal(signal.SIGTERM, self.handle_exit)
signal.signal(signal.SIGINT, self.handle_quit)
signal.signal(signal.SIGWINCH, self.handle_winch)
signal.signal(signal.SIGUSR1, self.handle_usr1)
signal.signal(signal.SIGABRT, self.handle_abort)
# Don't let SIGTERM and SIGUSR1 disturb active requests
# by interrupting system calls
if hasattr(signal, 'siginterrupt'): # python >= 2.6
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
if hasattr(signal, 'set_wakeup_fd'):
signal.set_wakeup_fd(self.PIPE[1])
示例14: main
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def main():
"""Parses the arguments and call worker()"""
# Set the signal handler
for s in [signal.SIGINT, signal.SIGTERM]:
signal.signal(s, shutdown)
signal.siginterrupt(s, False)
parser = ArgumentParser(description=__doc__)
parser.add_argument(
'--sensor', metavar='SENSOR[:SENSOR]',
help='sensor to check, optionally with a long name, defaults to all.',
)
parser.add_argument(
'--directory', metavar='DIR',
help='base directory (defaults to /ivre/passiverecon/).',
default="/ivre/passiverecon/",
)
parser.add_argument(
'--progname', metavar='PROG',
help='Program to run (defaults to ivre passiverecon2db).',
default="ivre passiverecon2db",
)
args = parser.parse_args()
if args.sensor is not None:
SENSORS.update(dict([args.sensor.split(':', 1)
if ':' in args.sensor
else [args.sensor, args.sensor]]))
sensor = args.sensor.split(':', 1)[0]
else:
sensor = None
worker(args.progname, args.directory, sensor=sensor)
示例15: test_without_siginterrupt
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import siginterrupt [as 別名]
def test_without_siginterrupt(self):
"""If a signal handler is installed and siginterrupt is not called
at all, when that signal arrives, it interrupts a syscall that's in
progress.
"""
i = self.readpipe_interrupted()
self.assertTrue(i)
# Arrival of the signal shouldn't have changed anything.
i = self.readpipe_interrupted()
self.assertTrue(i)