MCPcopy
hub / github.com/tensorlayer/TensorLayer / check_unfinished_task

Method check_unfinished_task

tensorlayer/db.py:692–738  ·  view source on GitHub ↗

Finds and runs a pending task. Parameters ----------- task_name : str The task name. kwargs : other parameters Users customized parameters such as description, version number. Examples --------- Wait until all tasks fi

(self, task_name=None, **kwargs)

Source from the content-addressed store, hash-verified

690 logging.info("[Database] Delete Task SUCCESS")
691
692 def check_unfinished_task(self, task_name=None, **kwargs):
693 """Finds and runs a pending task.
694
695 Parameters
696 -----------
697 task_name : str
698 The task name.
699 kwargs : other parameters
700 Users customized parameters such as description, version number.
701
702 Examples
703 ---------
704 Wait until all tasks finish in user's local console
705
706 >>> while not db.check_unfinished_task():
707 >>> time.sleep(1)
708 >>> print("all tasks finished")
709 >>> sess = tf.InteractiveSession()
710 >>> net = db.find_top_model(sess=sess, sort=[("test_accuracy", -1)])
711 >>> print("the best accuracy {} is from model {}".format(net._test_accuracy, net._name))
712
713 Returns
714 --------
715 boolean : True for success, False for fail.
716
717 """
718
719 if not isinstance(task_name, str): # is None:
720 raise Exception("task_name should be string")
721 self._fill_project_info(kwargs)
722
723 kwargs.update({'$or': [{'status': 'pending'}, {'status': 'running'}]})
724
725 # ## find task
726 # task = self.db.Task.find_one(kwargs)
727 task = self.db.Task.find(kwargs)
728
729 task_id_list = task.distinct('_id')
730 n_task = len(task_id_list)
731
732 if n_task == 0:
733 logging.info("[Database] No unfinished task - task_name: {}".format(task_name))
734 return False
735 else:
736
737 logging.info("[Database] Find {} unfinished task - task_name: {}".format(n_task, task_name))
738 return True
739
740 @staticmethod
741 def _print_dict(args):

Callers 1

dispatch_tasks.pyFile · 0.80

Calls 2

_fill_project_infoMethod · 0.95
updateMethod · 0.45

Tested by

no test coverage detected