本文整理汇总了Python中multiprocessing.Manager.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.stop方法的具体用法?Python Manager.stop怎么用?Python Manager.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Manager
的用法示例。
在下文中一共展示了Manager.stop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MPMain
# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import stop [as 别名]
class MPMain(object):
description = 'Description is not filled in a subclass'
def __init__(self, pid=os.getpid(), run=False):
self.pid = pid
self.mgr = Manager()
self.abort_event = self.mgr.Event()
self.argparser = None
self.args = None
signal.signal(signal.SIGINT, self.sig_handler)
signal.signal(signal.SIGTERM, self.sig_handler)
signal.signal(signal.SIGQUIT, self.sig_handler)
if run: self()
def __del__(self):
try: self.mgr.stop()
except: pass
def sig_handler(self, signal, frame):
if self.pid != os.getpid(): return
print('\nAborting. This may take some time '
'as not all operations could be stopped immediately.\n')
self.abort_event.set(); sleep(0.1)
clean_tmp_files()
def _main(self): pass
def argument(self, *args, **kwargs):
if self.argparser is None:
self.argparser = argparse.ArgumentParser(self.description)
self.argparser.add_argument(*args, **kwargs)
def parse_args(self):
self.args = self.argparser.parse_args()
def __call__(self, sys_exit=True, *args, **kwargs):
try: ret = self._main()
except SystemExit, e:
if sys_exit: sys.exit(e.code)
else: return e.code
except Exception, e:
self.abort_event.set()
print 'Unhandled Exception in MPMain:\n%s' % estr(e)
traceback.print_exc()
if sys_exit: sys.exit(1)
else: return 1