本文整理汇总了Python中os.killpg方法的典型用法代码示例。如果您正苦于以下问题:Python os.killpg方法的具体用法?Python os.killpg怎么用?Python os.killpg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.killpg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: raise_sigint
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def raise_sigint():
"""
Raising the SIGINT signal in the current process and all sub-processes.
os.kill() only issues a signal in the current process (without subprocesses).
CTRL+C on the console sends the signal to the process group (which we need).
"""
if hasattr(signal, 'CTRL_C_EVENT'):
# windows. Need CTRL_C_EVENT to raise the signal in the whole process group
os.kill(os.getpid(), signal.CTRL_C_EVENT)
else:
# unix.
pgid = os.getpgid(os.getpid())
if pgid == 1:
os.kill(os.getpid(), signal.SIGINT)
else:
os.killpg(os.getpgid(os.getpid()), signal.SIGINT)
示例2: terminate_process
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def terminate_process():
if m2ee:
logging.info("stopping app...")
if not m2ee.stop():
if not m2ee.terminate():
m2ee.kill()
try:
this_process = os.getpgid(0)
logging.debug(
"Terminating process group with pgid=%s", format(this_process)
)
os.killpg(this_process, signal.SIGTERM)
time.sleep(3)
os.killpg(this_process, signal.SIGKILL)
except OSError:
logging.exception("Failed to terminate all child processes")
示例3: destroy
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def destroy(self):
"""
Cleanup of all ROS publishers
"""
if self.stack_process and self.stack_process.poll() is None:
rospy.loginfo("Sending SIGTERM to stack...")
os.killpg(os.getpgid(self.stack_process.pid), signal.SIGTERM)
rospy.loginfo("Waiting for termination of stack...")
self.stack_process.wait()
time.sleep(5)
rospy.loginfo("Terminated stack.")
rospy.loginfo("Stack is no longer running")
self.world_info_publisher.unregister()
self.map_file_publisher.unregister()
self.vehicle_status_publisher.unregister()
self.vehicle_info_publisher.unregister()
self.waypoint_publisher.unregister()
self.stack_process = None
rospy.loginfo("Cleanup finished")
示例4: stop
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def stop(self):
self.logger.warn("bro stop...")
if not self.running:
self.logger.warn("bro running:{}".format(self.running))
return
self.running = False
gevent.sleep(2)
self.client_task = None
if self.sub_task is not None:
try:
self.logger.warn("bro killpg({})...".format(self.sub_task.pid))
os.killpg(self.sub_task.pid, signal.SIGTERM)
self.logger.warn("bro killpg({}) down.".format(self.sub_task.pid))
except Exception as ex:
self.logger.error("fail to kill the process, %s", ex)
traceback.print_exc()
self.sub_task.wait()
self.sub_task = None
self.logger.warn("bro stop down.")
示例5: stop
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def stop(self):
self.logger.info("stop tshark driver on interface %s for ports %s, with bpf filter %s", self.interface,
self.ports, self.bpf_filter)
self.running = False
if self.client_task:
self.client_task.join(timeout=2)
self.client_task = None
if self.sub_task is not None:
try:
if self.sub_task.isalive():
os.killpg(self.sub_task.pid, signal.SIGTERM)
self.sub_task.wait()
except Exception as ex:
traceback.print_exc()
self.logger.error("fail to kill subprocess %s", ex)
self.sub_task = None
示例6: kill_session
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def kill_session(session):
if os.path.isfile("/tmp/afl_multicore.PGID.%s" % session):
f = open("/tmp/afl_multicore.PGID.%s" % session)
pgids = f.readlines()
for pgid in pgids:
try:
print_ok("Killing jobs with PGID %s" % pgid.strip('\r\n'))
os.killpg(int(pgid), signal.SIGTERM)
except ProcessLookupError:
print_warn("No processes with PGID %s found!" % (pgid.strip('\r\n')))
f.close()
os.remove("/tmp/afl_multicore.PGID.%s" % session)
else:
print_err("PGID file '/tmp/afl_multicore.PGID.%s' not found! Aborting!" % session)
sys.exit(1)
示例7: tearDown
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def tearDown(self):
# stop TabPy
if self.process is not None:
if platform.system() == "Windows":
subprocess.call(["taskkill", "/F", "/T", "/PID", str(self.process.pid)])
else:
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
self.process.kill()
# after shutting down TabPy and before we start it again
# for next test give it some time to terminate.
time.sleep(5)
# remove temporary files
if self.delete_temp_folder:
os.remove(self.state_file_name)
os.remove(self.config_file_name)
shutil.rmtree(self.tmp_dir)
super(IntegTestBase, self).tearDown()
示例8: stop
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def stop(self, signal=None):
"""Stop the heroku local subprocess and all of its children.
"""
signal = signal or self.int_signal
self.out.log("Cleaning up local Heroku process...")
if self._process is None:
self.out.log("No local Heroku process was running.")
return
try:
os.killpg(os.getpgid(self._process.pid), signal)
self.out.log("Local Heroku process terminated.")
except OSError:
self.out.log("Local Heroku was already terminated.")
self.out.log(traceback.format_exc())
finally:
self._process = None
示例9: kill_em_all
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def kill_em_all(sig, frame):
"""
Terminate all processes while capturing a SIGINT from the user
"""
logger_gen.info('CTRL-C received, exiting')
if is_windows():
multiprocessing.sys.exit(1)
else:
pid = os.getpid()
pgid = os.getpgid(pid)
sid = os.getsid(os.getpid())
# if launched with --no-xserver
if pid == sid:
os.killpg(pgid, signal.SIGKILL)
else:
time.sleep(4)
multiprocessing.sys.exit(1)
示例10: exit_and_msg
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def exit_and_msg(msg):
traceback.print_stack()
exit_msg = "Service Stop by: " + msg
logging.exception(exit_msg)
# To make sure of terminating process exactly
os.killpg(0, signal.SIGKILL)
time.sleep(5)
os.kill(os.getpid(), signal.SIGKILL)
time.sleep(5)
os._exit(-1)
time.sleep(5)
sys.exit(-1)
示例11: _shocker_thread
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def _shocker_thread(self) -> None:
# Though this shares a name with the shocker thread used for submissions, where the process shocker thread
# is a fine scalpel that ends a TLE process with surgical precision, this is more like a rusty hatchet
# that beheads a misbehaving compiler.
#
# It's not very accurate: time starts ticking in the next line, regardless of whether the process is
# actually running, and the time is updated in 0.25s intervals. Nonetheless, it serves the purpose of
# not allowing the judge to die.
#
# See <https://github.com/DMOJ/judge/issues/141>
start_time = time.time()
while self.returncode is None:
if time.time() - start_time > self._time:
self.timed_out = True
try:
os.killpg(self.pid, signal.SIGKILL)
except OSError:
# This can happen if the process exits quickly
pass
break
time.sleep(0.25)
示例12: _shocker_thread
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def _shocker_thread(self):
# On Linux, ignored signals still cause a notification under ptrace.
# Hence, we use SIGWINCH, harmless and ignored signal to make wait4 return
# pt_process::monitor, causing time to be updated.
# On FreeBSD, a signal must not be ignored in order for wait4 to return.
# Hence, we swallow SIGSTOP, which should never be used anyway, and use it
# force an update.
wake_signal = signal.SIGSTOP if 'freebsd' in sys.platform else signal.SIGWINCH
self._spawned_or_errored.wait()
while not self._died.wait(1):
if self.execution_time > self._time or self.wall_clock_time > self._wall_time:
log.warning('Shocker activated and killed %d', self.pid)
self.kill()
self._is_tle = True
break
try:
os.killpg(self.pid, wake_signal)
except OSError:
pass
示例13: stop
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def stop(self, wait_term=True, force=False):
if self.state != 'started':
return
self.dbg('Stopping (pid {})'.format(self.proc.pid))
try:
os.killpg(os.getpgid(self.proc.pid), signal.SIGTERM)
except OSError as e:
self.log('killpg() failed: already dead? (%s): ignoring' % str(e))
wait_term = False
if wait_term:
# Wait for termination
self.wait_stopped(timeout=10, force=force)
else:
self.state = 'stopped'
self.dbg('now %s, runtime %ds' % (self.state, self.runtime()))
self.stdout_fd.close()
self.stderr_fd.close()
self.proc = None
示例14: stop
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def stop(self):
if self.process is None:
return
try:
os.killpg(os.getpgid(self.process.pid), self.stop_signal)
except OSError:
# Process is already gone
pass
else:
kill_time = time.time() + self.kill_after
while time.time() < kill_time:
if self.process.poll() is not None:
break
time.sleep(0.25)
else:
try:
os.killpg(os.getpgid(self.process.pid), 9)
except OSError:
# Process is already gone
pass
self.process = None
示例15: kill_proc
# 需要导入模块: import os [as 别名]
# 或者: from os import killpg [as 别名]
def kill_proc(self, proc):
"""
Stop the process if it is alive.
Input:
proc: dict: as created in start_proc()
Return:
str: information on what happened
"""
if proc["process"].poll() == None:
try:
pgid = os.getpgid(proc["process"].pid)
os.killpg(pgid, signal.SIGTERM)
except:
"""
Could already be dead
"""
proc["process"].terminate()
proc["runtime"] = time.time() - proc["start"]
proc["running"] = False
return "Process %s killed" % proc["process"].pid
return ""