def run(self, params): if share.get_if_run() == True: result_dict = {'code':1002,"data":{"message":"已经有一个任务在执行","taskid":"%s" % share.get_taskid()}} self.set_response(result_dict) return if params.has_key('mode') == False: result_dict = {'code':1003,"data":{"message":"缺少mode参数"}} self.set_response(result_dict) return elif params['mode'][0] != "monkey" and params['mode'][0] != 'autotest': self.set_response({'code':1004, "data":{"message":"mode参数错误"}}) return try: set_run_manager(RunTestManager(params['mode'][0])) self.taskid = get_run_manager().task_id share.set_taskid(get_run_manager().task_id) #设置全局共享taskid share.set_if_run(True) thread = threading.Thread(target=get_run_manager().start_run) thread.start() result_dict = {'code':0,"data":{"taskid f**k":"%s" % self.taskid,"message":"开始执行%s任务" % params['mode']}} self.set_response(result_dict) except Exception, e: traceback.print_exc() get_run_manager().stop_run()
def stop_run(self): share.set_if_run(False)