def mem_check(opts):
while True:
if opts['gc']:
try:
gc.collect()
except Exception as e:
logging.exception(repr(e) + ' while gc.collect()')
try:
rss = psutil.Process(os.getpid()).memory_info().rss
logging.info('current memory used: {rss}'.format(rss=rss))
if rss > opts['threshold']:
memory_dump(opts)
os.abort()
except Exception as e:
logging.exception(repr(e) + ' while checking memory usage')
finally:
time.sleep(opts['interval'])
python类abort()的实例源码
def app(self):
appuifw.app.title=ru(title)
appuifw.app.exit_key_handler=self.exit
self.i=1
self.console=Console.Console(True)
self.text=self.console.text
appuifw.app.body=self.console.text
self.text.color=255,0,0
self.text.font= "title",20
self.write("%s by %s"%(title,self.developer))
self.text.color=0,0,0
self.text.font= "title",18
if not len(socket.access_points()):
self.write("No Access Point is defined.Please add new APN.App will exit")
e32.ao_sleep(2)
os.abort()
else:
pass
self.write("Access Point: %s"%self.ap_list[self.apid_list.index(self.sets.APN)])
self.write("Find IP:%s"%self.insta(self.sets.IPHUNT))
self.write("Run Simple Server: %s"%self.yesno[self.sets.RUNSS])
appuifw.app.menu=[(ru("Start"),self.start),(ru("Settings"),self.settings),(ru("About"),self.about),(ru("Exit"),self.exit)]
def app(self):
appuifw.app.title=ru(title)
appuifw.app.exit_key_handler=self.exit
self.i=1
self.console=Console.Console(True)
self.text=self.console.text
appuifw.app.body=self.console.text
self.text.color=255,0,0
self.text.font= "title",20
self.write("%s by %s"%(title,self.developer))
self.text.color=0,0,0
self.text.font= "title",18
if not len(socket.access_points()):
self.write("No Access Point is defined.Please add new APN.App will exit")
e32.ao_sleep(2)
os.abort()
else:
pass
self.write("Access Point: %s"%self.ap_list[self.apid_list.index(self.sets.APN)])
self.write("Find IP:%s"%self.insta(self.sets.IPHUNT))
self.write("Run Simple Server: %s"%self.yesno[self.sets.RUNSS])
appuifw.app.menu=[(ru("Start"),self.start),(ru("Settings"),self.settings),(ru("About"),self.about),(ru("Exit"),self.exit)]
def _do_main(self, commands):
"""
:type commands: list of VSCtlCommand
"""
self._reset()
self._init_schema_helper()
self._run_prerequisites(commands)
idl_ = idl.Idl(self.remote, self.schema_helper)
seqno = idl_.change_seqno
while True:
self._idl_wait(idl_, seqno)
seqno = idl_.change_seqno
if self._do_vsctl(idl_, commands):
break
if self.txn:
self.txn.abort()
self.txn = None
# TODO:XXX
# ovsdb_symbol_table_destroy(symtab)
idl_.close()
def determineVideoDevice():
global video_device_searched
if video_device != None:
video_device_searched = video_device
print("Selected \"{}\" as video device...".format(video_device_searched))
return
path = "/dev/"
files = []
for i in os.listdir(path):
f = os.path.join(path, i)
if "/dev/video" in f:
files.append(f)
if len(files) > 0:
video_device_searched = files[0]
print("Selected \"{}\" as video device...".format(video_device_searched))
else:
video_device_searched = None
print("No video device found!")
os.abort()
def _do_main(self, commands):
"""
:type commands: list of VSCtlCommand
"""
self._reset()
self._init_schema_helper()
self._run_prerequisites(commands)
idl_ = idl.Idl(self.remote, self.schema_helper)
seqno = idl_.change_seqno
while True:
self._idl_wait(idl_, seqno)
seqno = idl_.change_seqno
if self._do_vsctl(idl_, commands):
break
if self.txn:
self.txn.abort()
self.txn = None
# TODO:XXX
# ovsdb_symbol_table_destroy(symtab)
idl_.close()
def start_mem_check_thread(threshold=1024 * 1024 * 1024,
gc=False,
size_range=None,
interval=1
):
"""
Start a thread in background and in daemon mode, to watch memory usage.
If memory this process is using beyond `threshold`, a memory usage profile
is made and is written to root logger. And process is aborted.
`threshold`: maximum memory a process can use before abort.
`gc`: whether to run gc every time before checking memory usage.
`size_range`: in tuple, dump only object of size in this range.
`interval`: memory check interval.
"""
options = {
'threshold': threshold,
'gc': gc,
'size_range': size_range,
'interval': interval,
}
th = threading.Thread(target=mem_check, args=(options,))
th.daemon = True
th.start()
return th
def exit(self):
q=appuifw.query(u"Do you really want to Exit","query")
if q:
try:
self.timerip.cancel()
self.timert.cancel()
appuifw.app.set_exit()
except:
os.abort()
def exit():
os.abort()
def test_run_abort(self):
# returncode handles signal termination
with _SuppressCoreFiles():
p = subprocess.Popen([sys.executable, "-c",
'import os; os.abort()'])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def test_run_abort(self):
# returncode handles signal termination
with _SuppressCoreFiles():
p = subprocess.Popen([sys.executable, "-c",
"import os; os.abort()"])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def test_run_abort(self):
# returncode handles signal termination
with _SuppressCoreFiles():
p = subprocess.Popen([sys.executable, "-c",
"import os; os.abort()"])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def exit():
sets.LOGIN = 0
sets.save()
os.abort()
def exit(self):
q=appuifw.query(u"Do you really want to Exit","query")
if q:
try:
self.timerip.cancel()
self.timert.cancel()
appuifw.app.set_exit()
except:
os.abort()
pipeline.py 文件源码
项目:Comparative-Annotation-Toolkit
作者: ComparativeGenomicsToolkit
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def __start(self):
"do work of starting the process"
self.statusPipe = _StatusPipe()
self.started = True # do first to prevent restarts on error
self.pid = os.fork()
if self.pid == 0:
try:
self.__childStart()
finally:
os.abort() # should never make it here
else:
self.__parentStart()
def test_run_abort(self):
# returncode handles signal termination
with _SuppressCoreFiles():
p = subprocess.Popen([sys.executable, "-c",
'import os; os.abort()'])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def not_reached():
os.abort()
def test_run_abort(self):
# returncode handles signal termination
with _SuppressCoreFiles():
p = subprocess.Popen([sys.executable, "-c",
"import os; os.abort()"])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def test_run_abort(self):
# returncode handles signal termination
with support.SuppressCrashReport():
p = subprocess.Popen([sys.executable, "-c",
'import os; os.abort()'])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def test_run_abort(self):
# returncode handles signal termination
with _SuppressCoreFiles():
p = subprocess.Popen([sys.executable, "-c",
"import os; os.abort()"])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def setUp(self):
self.mox = mox.Mox()
self.mox.StubOutWithMock(os, 'abort')
shutdown._shutting_down = False
shutdown._num_terminate_requests = 0
self._sigint_handler = signal.getsignal(signal.SIGINT)
self._sigterm_handler = signal.getsignal(signal.SIGTERM)
def test_async_terminate_abort(self):
os.abort()
self.mox.ReplayAll()
shutdown._async_terminate()
self.assertTrue(shutdown._shutting_down)
shutdown._async_terminate()
shutdown._async_terminate()
self.mox.VerifyAll()
def _async_terminate(*_):
async_quit()
global _num_terminate_requests
_num_terminate_requests += 1
if _num_terminate_requests == 1:
logging.info('Shutting down.')
if _num_terminate_requests >= 3:
logging.error('Received third interrupt signal. Terminating.')
os.abort()
def test_run_abort(self):
# returncode handles signal termination
with support.SuppressCrashReport():
p = subprocess.Popen([sys.executable, "-c",
'import os; os.abort()'])
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)
def not_reached():
os.abort()