我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用signal.SIGCONT。
def resume(self): """Resume the process by sending a SIGCONT to the child This method is a no-op on Windows """ try: self.command_process.send_signal(signal.SIGCONT) except (ValueError, AttributeError, OSError): pass
def execute(self,dt): if self.finished: return "finished" if not self.running: self.process = Process(target = executeInProcessGroup, args = (self,)) self.process.start() print "timeshare child PID:",self.process.pid os.setpgid(self.process.pid,self.process.pid) print "timeshare process group",os.getpgid(self.process.pid) assert os.getpgid(self.process.pid) == self.process.pid print "my process group",os.getpgrp(),"which should be",os.getpgid(0) assert os.getpgid(self.process.pid) != os.getpgid(0) self.running = True else: os.killpg(self.process.pid, signal.SIGCONT) self.process.join(dt) if self.process.is_alive(): os.killpg(self.process.pid, signal.SIGSTOP) return "still running" else: self.finished = True return self.q.get()
def resume(self): """Resume process execution with SIGCONT pre-emptively checking whether PID has been reused. On Windows this has the effect of resuming all process threads. """ if POSIX: self._send_signal(signal.SIGCONT) else: # pragma: no cover self._proc.resume()
def terminate(self, force=False): '''This forces a child process to terminate. It starts nicely with SIGHUP and SIGINT. If "force" is True then moves onto SIGKILL. This returns True if the child was terminated. This returns False if the child could not be terminated. ''' if not self.isalive(): return True try: self.kill(signal.SIGHUP) time.sleep(self.delayafterterminate) if not self.isalive(): return True self.kill(signal.SIGCONT) time.sleep(self.delayafterterminate) if not self.isalive(): return True self.kill(signal.SIGINT) time.sleep(self.delayafterterminate) if not self.isalive(): return True if force: self.kill(signal.SIGKILL) time.sleep(self.delayafterterminate) if not self.isalive(): return True else: return False return False except OSError: # I think there are kernel timing issues that sometimes cause # this to happen. I think isalive() reports True, but the # process is dead to the kernel. # Make one last attempt to see if the kernel is up to date. time.sleep(self.delayafterterminate) if not self.isalive(): return True else: return False
def teardown(self): self._send_signal(signal.SIGCONT)
def terminate(self, force=False): """This forces a child process to terminate. It starts nicely with SIGHUP and SIGINT. If "force" is True then moves onto SIGKILL. This returns True if the child was terminated. This returns False if the child could not be terminated. """ if not self.isalive(): return True try: self.kill(signal.SIGHUP) time.sleep(self.delayafterterminate) if not self.isalive(): return True self.kill(signal.SIGCONT) time.sleep(self.delayafterterminate) if not self.isalive(): return True self.kill(signal.SIGINT) time.sleep(self.delayafterterminate) if not self.isalive(): return True if force: self.kill(signal.SIGKILL) time.sleep(self.delayafterterminate) if not self.isalive(): return True else: return False return False except OSError, e: # I think there are kernel timing issues that sometimes cause # this to happen. I think isalive() reports True, but the # process is dead to the kernel. # Make one last attempt to see if the kernel is up to date. time.sleep(self.delayafterterminate) if not self.isalive(): return True else: return False
def unfreeze(self, nodes=None): task = {'kill': {'grep': self.grep, 'sig': signal.SIGCONT}} self._run_task(nodes, task, 'Unfreeze')
def run_master(mothership_url, workingdir, master_of): with tempdir(workingdir, 'mothership_afl_master_') as directory: logger.info('Starting master in %s' % (directory,)) master = MothershipMaster(mothership_url, directory, master_of) os.makedirs(master.campaign_directory) download_afl(mothership_url, directory) download_queue(master.download_url, master.campaign_directory, [], executable_name=master.program) master.start() while not master.instance.process: time.sleep(1) global active while not master.instance.process.poll(): #time.sleep(5 * 60) time.sleep(10) try: campaign_active = requests.get(mothership_url + '/fuzzers/is_active/%d' % master_of).json()['active'] except Exception: continue if active != campaign_active: if campaign_active: logger.warn('Resuming master') os.kill(master.instance.process.pid, signal.SIGCONT) else: logger.warn('Pausing master') os.kill(master.instance.process.pid, signal.SIGSTOP) active = campaign_active master.join()
def resume(self): try: # noinspection PyUnresolvedReferences self._process.send_signal(signal.SIGCONT) except AttributeError: logger.warning( 'SIGCONT is not available on this platform' )
def resume(self): """Resume process execution with SIGCONT pre-emptively checking whether PID has been reused. On Windows this has the effect of resuming all process threads. """ if _POSIX: self._send_signal(signal.SIGCONT) else: self._proc.resume()
def wait_for_active_job(signal_to_send=None): """ Wait for the active job to finish, to be killed by SIGINT, or to be suspended by ctrl-z. """ _clear_dead_jobs() act = builtins.__xonsh_active_job__ if act is None: return job = builtins.__xonsh_all_jobs__[act] obj = job['obj'] if job['bg']: return pgrp = job['pgrp'] obj.done = False # give the terminal over to the fg process _give_terminal_to(pgrp) # if necessary, send the specified signal to this process # (this hook was added because vim, emacs, etc, seem to need to have # the terminal when they receive SIGCONT from the "fg" command) if signal_to_send is not None: os.kill(obj.pid, signal_to_send) _, s = os.waitpid(obj.pid, os.WUNTRACED) if os.WIFSTOPPED(s): obj.done = True job['bg'] = True job['status'] = 'stopped' print() # get a newline because ^Z will have been printed print_one_job(act) elif os.WIFSIGNALED(s): print() # get a newline because ^C will have been printed if obj.poll() is not None: builtins.__xonsh_active_job__ = None _give_terminal_to(_shell_pgrp) # give terminal back to the shell
def terminate(self): if self.terminated: return self.terminated = True self.remove_watch() self.change_focus(False) if self.pid > 0: self.set_termsize(0, 0) for sig in (signal.SIGHUP, signal.SIGCONT, signal.SIGINT, signal.SIGTERM, signal.SIGKILL): try: os.kill(self.pid, sig) pid, status = os.waitpid(self.pid, os.WNOHANG) except OSError: break if pid == 0: break time.sleep(0.1) try: os.waitpid(self.pid, 0) except OSError: pass os.close(self.master)
def test_suspend_doesnt_crash(self): import os import shutil import signal import subprocess import sys import tempfile self.tempdir = tempfile.mkdtemp('test_suspend') filename = os.path.join(self.tempdir, 'test_suspend.py') fd = open(filename, "w") fd.write("""import eventlet eventlet.Timeout(0.5) try: eventlet.listen(("127.0.0.1", 0)).accept() except eventlet.Timeout: print("exited correctly") """) fd.close() python_path = os.pathsep.join(sys.path + [self.tempdir]) new_env = os.environ.copy() new_env['PYTHONPATH'] = python_path p = subprocess.Popen([sys.executable, os.path.join(self.tempdir, filename)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=new_env) eventlet.sleep(0.4) # wait for process to hit accept os.kill(p.pid, signal.SIGSTOP) # suspend and resume to generate EINTR os.kill(p.pid, signal.SIGCONT) output, _ = p.communicate() lines = output.decode('utf-8', 'replace').splitlines() assert "exited correctly" in lines[-1], output shutil.rmtree(self.tempdir)
def resume(self): """Resume the process by sending a SIGCONT to the child""" try: self.command_process.stdin.write("CONT\n") self.command_process.stdin.flush() except IOError as exc: if exc.errno == 32: # Broken pipe, guard exited return raise item = self.resp_queue.get() if item[1] != "CONT" and item[1] is not None: raise SandboxError("Bad response from jailguard after resume, %s" % (item,))
def signal(self, sig): """ Signal the process of an event. """ if sig == signal.SIGKILL: self.kill() elif sig == signal.SIGTERM: self.terminate() elif sig == signal.SIGSTOP: self.pause() elif sig == signal.SIGCONT: self.unpause() else: self.on_signal(sig)
def unpause(self): # continue is a reserved word """ Continue the process after it's been paused """ self.signal(signal.SIGCONT)
def kill_and_wait(pid, pidfile): # The NGAS server should nicely shut down itself after receiving this signal os.kill(pid, signal.SIGTERM) # We previously checked that the pidfile was gone, but this is not enough # In some cases the main thread finished correctly, but there are other # threads (e.g., HTTP servicing threads) that are still running, # and thus the PID file disappears but the process is still ongoing tries = 0 max_tries = 20 sleep_period = 1 start = time.time() while tries < max_tries: # SIGCONT can be sent many times without fear of side effects # If we get ESRCH then the process has finished try: os.kill(pid, signal.SIGCONT) except OSError as e: if e.errno == errno.ESRCH: # Bingo! the process is gone break tries += 1 time.sleep(sleep_period) sys.stdout.write('.') sys.stdout.flush() sys.stdout.write('\n') sys.stdout.flush() end = time.time() ret = 0x00 # We waited a lot but the process is still there, kill it with 9 if tries == max_tries: err("Process didn't die after %.2f [s], killing it with -9" % (end-start)) os.kill(pid, signal.SIGKILL) ret += 0x01 # The process should have removed its own pidfile... if os.path.exists(pidfile): err("Removing PID file manually, the daemon process didn't remove it by itself") os.unlink(pidfile) ret += 0x02 return ret