importsysimporttimefromabcimportABCMeta,abstractmethodclassTrainer(object):__metaclass__=ABCMetadef__init__(self,config):self._status_processor={}self._context={'status':'uninit','is_exit':False}defregist_context_processor(self,status_name,processor):self._status_processor[status_name]=processordefcontext_process(self,context):ifcontext['status']inself._status_processor:self._status_processor[context['status']](context)else:self.other_status_processor(context)defother_status_processor(self,context):print('unknow context_status:%s, do nothing'%context['status'])time.sleep(60)defreload_train_context(self):passdefrun(self):whileTrue:self.reload_train_context()self.context_process(self._context)ifself._context['is_exit']:break