Python signal.siginterrupt() Examples
The following are 30
code examples of signal.siginterrupt().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
signal
, or try the search function
.
Example #1
Source File: _signals.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #2
Source File: Droid.py From pilot with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: proctools.py From pycopia with Apache License 2.0 | 6 votes |
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
Example #4
Source File: Yoda.py From pilot with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: profiler.py From pyFileFixity with MIT License | 6 votes |
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)
Example #6
Source File: _signals.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #7
Source File: main.py From vise with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: taskd.py From allura with Apache License 2.0 | 6 votes |
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()
Example #9
Source File: _signals.py From python-for-android with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: worker.py From lambda-text-extractor with Apache License 2.0 | 6 votes |
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)
Example #11
Source File: worker.py From lambda-text-extractor with Apache License 2.0 | 6 votes |
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)
Example #12
Source File: base.py From Flask-P2P with MIT License | 6 votes |
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)
Example #13
Source File: worker.py From Galaxy_Plugin_Bethesda with MIT License | 6 votes |
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)
Example #14
Source File: test_signal.py From android_universal with MIT License | 5 votes |
def test_siginterrupt_off(self): # If a signal handler is installed and siginterrupt is called with # a false value for the second argument, when that signal arrives, it # does not interrupt a syscall that's in progress. interrupted = self.readpipe_interrupted(False) self.assertFalse(interrupted)
Example #15
Source File: test_signal.py From android_universal with MIT License | 5 votes |
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. interrupted = self.readpipe_interrupted(None) self.assertTrue(interrupted)
Example #16
Source File: test_signal.py From android_universal with MIT License | 5 votes |
def test_siginterrupt_on(self): # If a signal handler is installed and siginterrupt is called with # a true value for the second argument, when that signal arrives, it # interrupts a syscall that's in progress. interrupted = self.readpipe_interrupted(True) self.assertTrue(interrupted)
Example #17
Source File: gtk2reactor.py From python-for-android with Apache License 2.0 | 5 votes |
def _handleSignals(self): # Let the base class do its thing, but pygtk is probably # going to stomp on us so go beyond that and set up some # signal handling which pygtk won't mess with. This would # be better done by letting this reactor select a # different implementation of installHandler for # _SIGCHLDWaker to use. Then, at least, we could fall # back to our extension module. See #4286. from twisted.internet.process import reapAllProcesses as _reapAllProcesses base._SignalReactorMixin._handleSignals(self) signal.signal(signal.SIGCHLD, lambda *a: self.callFromThread(_reapAllProcesses)) if getattr(signal, "siginterrupt", None) is not None: signal.siginterrupt(signal.SIGCHLD, False) # Like the base, reap processes now in case a process # exited before the handlers above were installed. _reapAllProcesses() # The input_add function in pygtk1 checks for objects with a # 'fileno' method and, if present, uses the result of that method # as the input source. The pygtk2 input_add does not do this. The # function below replicates the pygtk1 functionality. # In addition, pygtk maps gtk.input_add to _gobject.io_add_watch, and # g_io_add_watch() takes different condition bitfields than # gtk_input_add(). We use g_io_add_watch() here in case pygtk fixes this # bug.
Example #18
Source File: test_signal.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_siginterrupt_off(self): i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 0)) self.assertEquals(i, False)
Example #19
Source File: test_signal.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_siginterrupt_off(self): i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 0)) self.assertEquals(i, False)
Example #20
Source File: test_signal.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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. interrupted = self.readpipe_interrupted(None) self.assertTrue(interrupted)
Example #21
Source File: test_signal.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_siginterrupt_on(self): # If a signal handler is installed and siginterrupt is called with # a true value for the second argument, when that signal arrives, it # interrupts a syscall that's in progress. interrupted = self.readpipe_interrupted(True) self.assertTrue(interrupted)
Example #22
Source File: test_signal.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_siginterrupt_off(self): # If a signal handler is installed and siginterrupt is called with # a false value for the second argument, when that signal arrives, it # does not interrupt a syscall that's in progress. interrupted = self.readpipe_interrupted(False) self.assertFalse(interrupted)
Example #23
Source File: test_signal.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_siginterrupt_on(self): i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 1)) self.assertEquals(i, True)
Example #24
Source File: worker.py From sanic with MIT License | 5 votes |
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)
Example #25
Source File: test_signal.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_siginterrupt_on(self): i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 1)) self.assertEquals(i, True)
Example #26
Source File: test_signal.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_siginterrupt_off(self): """If a signal handler is installed and siginterrupt is called with a false value for the second argument, when that signal arrives, it does not interrupt a syscall that's in progress. """ signal.siginterrupt(self.signum, 0) i = self.readpipe_interrupted() self.assertFalse(i) # Arrival of the signal shouldn't have changed anything. i = self.readpipe_interrupted() self.assertFalse(i)
Example #27
Source File: test_signal.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_siginterrupt_on(self): """If a signal handler is installed and siginterrupt is called with a true value for the second argument, when that signal arrives, it interrupts a syscall that's in progress. """ signal.siginterrupt(self.signum, 1) i = self.readpipe_interrupted() self.assertTrue(i) # Arrival of the signal shouldn't have changed anything. i = self.readpipe_interrupted() self.assertTrue(i)
Example #28
Source File: test_signal.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #29
Source File: server.py From angrdbg with BSD 2-Clause "Simplified" License | 5 votes |
def _accept_method(self, sock): self.num_conns -= 1 if self.num_conns == 1: t = threading.Thread( target=self._authenticate_and_serve_client, args=[sock]) t.start() self.thread = t else: pid = os.fork() if pid == 0: # child try: self.logger.debug("child process created") # 76: call signal.siginterrupt(False) in forked child signal.siginterrupt(signal.SIGCHLD, False) self.listener.close() self.clients.clear() self._authenticate_and_serve_client(sock) except BaseException: self.logger.exception( "child process terminated abnormally") else: self.logger.debug("child process terminated") finally: self.logger.debug("child terminated") os._exit(0) else: # parent self.proc = pid sock.close() if self.num_conns == 0: self.done_event.set() self.listener.close() self.join()
Example #30
Source File: workarounds.py From accelerator with Apache License 2.0 | 5 votes |
def __init__(self, signal_names=['SIGINFO'], key_values=[20], skip_input_if_possible=True): """signal_names is a list of signal names, which will be listened for if they exist. key_values is a list of (terminal input) key values, each will be considered equivalent of a signal if pressed. If skip_input_if_possible is True no input will be read if all signals exist. No differentiation is made between the signals.""" self.key_values = set(key_values) self.restore = {} self.signal_set = False self.clean = False self.use_input = False all_sigs = True atexit.register(self.cleanup) for name in signal_names: sig = getattr(signal, name, None) if sig is not None: old = signal.signal(sig, self.signal_arrived) self.restore[sig] = old signal.siginterrupt(sig, False) else: all_sigs = False if all_sigs and skip_input_if_possible: return self.tc_original = termios.tcgetattr(0) tc_changed = list(self.tc_original) tc_changed[3] &= ~(termios.ICANON | termios.IEXTEN) self.use_input = True termios.tcsetattr(0, termios.TCSADRAIN, tc_changed)