本文整理汇总了Python中os._exit方法的典型用法代码示例。如果您正苦于以下问题:Python os._exit方法的具体用法?Python os._exit怎么用?Python os._exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os._exit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: daemonize
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def daemonize(logfile = None):
# Fork once
if os.fork() != 0:
os._exit(0)
# Create new session
os.setsid()
if os.fork() != 0:
os._exit(0)
os.chdir('/')
fd = os.open('/dev/null', os.O_RDWR)
os.dup2(fd, sys.__stdin__.fileno())
if logfile != None:
fake_stdout = open(logfile, 'a', 1)
sys.stdout = fake_stdout
sys.stderr = fake_stdout
fd = fake_stdout.fileno()
os.dup2(fd, sys.__stdout__.fileno())
os.dup2(fd, sys.__stderr__.fileno())
if logfile == None:
os.close(fd)
示例2: process_request
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def process_request(self, request, client_address):
"""Fork a new subprocess to process the request."""
pid = os.fork()
if pid:
# Parent process
if self.active_children is None:
self.active_children = []
self.active_children.append(pid)
self.close_request(request)
return
else:
# Child process.
# This must never return, hence os._exit()!
try:
self.finish_request(request, client_address)
self.shutdown_request(request)
os._exit(0)
except:
try:
self.handle_error(request, client_address)
self.shutdown_request(request)
finally:
os._exit(1)
示例3: run
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def run(self):
cmd_line = self._mk_cmd_line()
logger.info(" ".join(cmd_line))
try:
run_with_logging(cmd_line, logger)
except subprocess.CalledProcessError as e:
logging.error(e, exc_info=True)
# exit luigi with the same exit code as the python dataflow job proccess
# In this way users can easily exit the job with code 50 to avoid Styx retries
# https://github.com/spotify/styx/blob/master/doc/design-overview.md#workflow-state-graph
os._exit(e.returncode)
self.on_successful_run()
if self.validate_output():
self._publish_outputs()
else:
raise ValueError("Output is not valid")
示例4: forked_run_report
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def forked_run_report(item):
# for now, we run setup/teardown in the subprocess
# XXX optionally allow sharing of setup/teardown
from _pytest.runner import runtestprotocol
EXITSTATUS_TESTEXIT = 4
import marshal
def runforked():
try:
reports = runtestprotocol(item, log=False)
except KeyboardInterrupt:
os._exit(EXITSTATUS_TESTEXIT)
return marshal.dumps([serialize_report(x) for x in reports])
ff = py.process.ForkedFunc(runforked)
result = ff.waitfinish()
if result.retval is not None:
report_dumps = marshal.loads(result.retval)
return [runner.TestReport(**x) for x in report_dumps]
else:
if result.exitstatus == EXITSTATUS_TESTEXIT:
pytest.exit("forked test item %s raised Exit" % (item,))
return [report_process_crash(item, result)]
示例5: maybe_start_cleaner_thread
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def maybe_start_cleaner_thread(self):
if not self.over_limit():
return
# exit immediately if another cleaner is active
cleaner_lock = os.path.join(self.pcache_dir, ".clean")
if self.lock_file(cleaner_lock, blocking=False):
self.log(INFO, "cleanup not starting: %s locked", cleaner_lock)
return
# see http://www.faqs.org/faqs/unix-faq/faq/part3/section-13.html
# for explanation of double-fork
pid = os.fork()
if pid: # parent
os.waitpid(pid, 0)
return
else: # child
self.daemonize()
pid = os.fork()
if pid:
os._exit(0)
# grandchild
self.clean_cache()
self.unlock_file(cleaner_lock)
os._exit(0)
示例6: on_timeout
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def on_timeout():
logger.debug("cli timeout ")
# Timeout should have been handled by the orchestrator, if the cli timeout
# has been reached, something is probably wrong : dump threads.
for th in threading.enumerate():
print(th)
traceback.print_stack(sys._current_frames()[th.ident])
print()
if orchestrator is None:
logger.debug("cli timeout with no orchestrator ?")
return
global timeout_stopped
timeout_stopped = True
# Stopping agents can be rather long, we need a big timeout !
logger.debug("stop agent on cli timeout ")
orchestrator.stop_agents(20)
logger.debug("stop orchestrator on cli timeout ")
orchestrator.stop()
_results("TIMEOUT")
# sys.exit(0)
os._exit(2)
示例7: on_timeout
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def on_timeout():
global result, output_file
global start_t
duration = time.time() - start_t
print("TIMEOUT when distributing")
logger.info("cli timeout when distributing")
for th in threading.enumerate():
print(th)
traceback.print_stack(sys._current_frames()[th.ident])
result["status"] = "TIMEOUT"
result["inputs"]["duration"] = duration
if output_file is not None:
with open(output_file, encoding="utf-8", mode="w") as fo:
fo.write(yaml.dump(result))
print(yaml.dump(result))
#os._exit(0)
sys.exit(0)
示例8: _got_log
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def _got_log(self, event):
print(event.context, event.category, event.text)
if event.context.traceId in self.context:
self.results.add((event.category, event.text))
if self.expected == self.results:
print("Got expected messages!")
self.mdk.stop()
os._exit(0) # Some MDK bug or something
else:
print("No full results yet, will keep trying: {} != {}".format(
self.expected, self.results))
if time.time() - self.start > 60:
print("Took more than 60 seconds, giving up.")
self.mdk.stop()
sys.exit(1)
示例9: fence_shutdown_mysql
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def fence_shutdown_mysql(port, dry_run):
""" Shutdown fenced box
Args:
A port for mysql instance
"""
log.info('checking security group and stop_mysql_fencing file exist')
if host_utils.get_security_group() == \
environment_specific.VPC_FENCE_DB_GROUP \
and not os.path.exists(TOUCH_FOR_NO_STOP_MYSQL_FENCING):
if dry_run:
log.info("In dry_run mode: Do Not actually shutdown "
"mysql_in_fence, exiting now")
os._exit(environment_specific.DRY_RUN_EXIT_CODE)
host_utils.stop_mysql(port)
else:
return
示例10: parse_body
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def parse_body(self, response):
global crawl_counter
try:
crawl_counter += 1
if crawl_counter > max_crawl_limit:
os._exit(0)
matches = rules.match(data=response.body)
if matches:
for match in matches:
print "[+] URL:", response.request.url, "Matched YARA Rule:", match
if debug:
print "[*] Matched body response:", response.body.decode("utf-8")
txt = "URL: " + response.request.url + " Matched YARA Rule: " + str(match)
log(txt)
except Exception as e:
# if debug:
print str(e)
示例11: __exit__
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def __exit__(self, *exc_info):
if self.proc is not None: ## worker
exceptOccurred = exc_info[0] is not None ## hit an exception during processing.
try:
if exceptOccurred:
sys.excepthook(*exc_info)
finally:
#print os.getpid(), 'exit'
os._exit(1 if exceptOccurred else 0)
else: ## parent
if self.showProgress:
try:
self.progressDlg.__exit__(None, None, None)
except Exception:
pass
示例12: external_stop
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def external_stop(self, force):
"""
Stop signal by server.
"""
# only the master processes handles the regular stop signal from the server, sending a SIGINT to
# all its child (means to us, non-master process)
if not self.is_master_process():
if force:
# make sure even the subprocess dies really on force
os._exit(1)
return
self.logger.warning("Received stop signal by server.")
if not self.stop_requested_force:
self.stop_requested_force = force
raise_sigint()
示例13: process_request
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def process_request(self, request, client_address):
"""Fork a new subprocess to process the request."""
self.collect_children()
pid = os.fork()
if pid:
# Parent process
if self.active_children is None:
self.active_children = []
self.active_children.append(pid)
self.close_request(request) #close handle in parent process
return
else:
# Child process.
# This must never return, hence os._exit()!
try:
self.finish_request(request, client_address)
self.shutdown_request(request)
os._exit(0)
except:
try:
self.handle_error(request, client_address)
self.shutdown_request(request)
finally:
os._exit(1)
示例14: _spawn_posix
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
log.info(' '.join(cmd))
if dry_run:
return
exec_fn = search_path and os.execvp or os.execv
pid = os.fork()
if pid == 0: # in the child
try:
exec_fn(cmd[0], cmd)
except OSError, e:
sys.stderr.write("unable to execute %s: %s\n" %
(cmd[0], e.strerror))
os._exit(1)
sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
os._exit(1)
示例15: process_request
# 需要导入模块: import os [as 别名]
# 或者: from os import _exit [as 别名]
def process_request(self, request, client_address):
"""Fork a new subprocess to process the request."""
self.collect_children()
pid = os.fork()
if pid:
# Parent process
if self.active_children is None:
self.active_children = set()
self.active_children.add(pid)
self.close_request(request) #close handle in parent process
return
else:
# Child process.
# This must never return, hence os._exit()!
try:
self.finish_request(request, client_address)
self.shutdown_request(request)
os._exit(0)
except:
try:
self.handle_error(request, client_address)
self.shutdown_request(request)
finally:
os._exit(1)