class_docstr: It is a MongoDB based manager that help you to manage data, network architecture, parameters and logging.
  
  Parameters
  -------------
  ip : str
      Localhost or IP address.
  port : int
      Port number.
  dbname : str
      Database name.
  username : str or None
      User name, set to None if you do not need authentication.
  password : str
      Password.
  project_name : str or None
      Experiment key for this entire project, similar with the repository name of Github.
  
  Attributes
  ------------
  ip, port, dbname and other input parameters : see above
      See above.
  project_name : str
      The given project name, if no given, set to the script name.
  db : mongodb client
      See ``pymongo.MongoClient``.
class_docstr_tok: ["It","is","a","MongoDB","based","manager","that","help","you","to","manage","data",",","network","architecture",",","parameters","and","logging",".","Parameters","--","--","--","--","--","--","-","ip",":","str","Localhost","or","IP","address",".","port",":","int","Port","number",".","dbname",":","str","Database","name",".","username",":","str","or","None","User","name",",","set","to","None","if","you","do","not","need","authentication",".","password",":","str","Password",".","project_name",":","str","or","None","Experiment","key","for","this","entire","project",",","similar","with","the","repository","name","of","Github",".","Attributes","--","--","--","--","--","--","ip",",","port",",","dbname","and","other","input","parameters",":","see","above","See","above",".","project_name",":","str","The","given","project","name",",","if","no","given",",","set","to","the","script","name",".","db",":","mongodb","client","See","``","pymongo.MongoClient","``","."]
docstr: Finds and runs a pending task that in the first of the sorting list.
  
  Parameters
  -----------
  task_name : str
      The task name.
  sort : List of tuple
      PyMongo sort comment, search "PyMongo find one sorting" and `collection level operations <http://api.mongodb.com/python/current/api/pymongo/collection.html>`__ for more details.
  kwargs : other parameters
      Users customized parameters such as description, version number.
  
  Examples
  ---------
  Monitors the database and pull tasks to run
  >>> while True:
  >>>     print("waiting task from distributor")
  >>>     db.run_top_task(task_name='mnist', sort=[("time", -1)])
  >>>     time.sleep(1)
  
  Returns
  --------
  boolean : True for success, False for fail.
docstr_tok: ["Finds","and","runs","a","pending","task","that","in","the","first","of","the","sorting","list",".","Parameters","--","--","--","--","--","-","task_name",":","str","The","task","name",".","sort",":","List","of","tuple","PyMongo","sort","comment",",","search","``","PyMongo","find","one","sorting","''","and","`","collection","level","operations","<","http",":","\/\/api.mongodb.com\/python\/current\/api\/pymongo\/collection.html",">","`","__","for","more","details",".","kwargs",":","other","parameters","Users","customized","parameters","such","as","description",",","version","number",".","Examples","--","--","--","--","-","Monitors","the","database","and","pull","tasks","to","run",">",">",">","while","True",":",">",">",">","print","(","``","waiting","task","from","distributor","''",")",">",">",">","db.run_top_task","(","task_name='mnist","'",",","sort=","[","(","``","time","''",",","-1",")","]",")",">",">",">","time.sleep","(","1",")","Returns","--","--","--","--","boolean",":","True","for","success",",","False","for","fail","."]
code: def run_top_task(self, task_name=None, sort=None, **kwargs):
      """Finds and runs a pending task that in the first of the sorting list.
  
      Parameters
      -----------
      task_name : str
          The task name.
      sort : List of tuple
          PyMongo sort comment, search "PyMongo find one sorting" and `collection level operations <http://api.mongodb.com/python/current/api/pymongo/collection.html>`__ for more details.
      kwargs : other parameters
          Users customized parameters such as description, version number.
  
      Examples
      ---------
      Monitors the database and pull tasks to run
      >>> while True:
      >>>     print("waiting task from distributor")
      >>>     db.run_top_task(task_name='mnist', sort=[("time", -1)])
      >>>     time.sleep(1)
  
      Returns
      --------
      boolean : True for success, False for fail.
      """
      if not isinstance(task_name, str):  # is None:
          raise Exception("task_name should be string")
      self._fill_project_info(kwargs)
      kwargs.update({"status": "pending"})
  
      # find task and set status to running
      task = self.db.Task.find_one_and_update(
          kwargs, {"$set": {"status": "running"}}, sort=sort
      )
  
      # try:
      # get task info e.g. hyper parameters, python script
      if task is None:
          logging.info(
              "[Database] Find Task FAIL: key: {} sort: {}".format(
                  task_name, sort
              )
          )
          return False
      else:
          logging.info(
              "[Database] Find Task SUCCESS: key: {} sort: {}".format(
                  task_name, sort
              )
          )
      _datetime = task["time"]
      _script = task["script"]
      _id = task["_id"]
      _hyper_parameters = task["hyper_parameters"]
      _saved_result_keys = task["saved_result_keys"]
      logging.info("  hyper parameters:")
      for key in _hyper_parameters:
          globals()[key] = _hyper_parameters[key]
          logging.info("    {}: {}".format(key, _hyper_parameters[key]))
      # run task
      s = time.time()
      logging.info(
          "[Database] Start Task: key: {} sort: {} push time: {}".format(
              task_name, sort, _datetime
          )
      )
      _script = _script.decode("utf-8")
      with tf.Graph().as_default():  #  # as graph: # clear all TF graphs
          exec(_script, globals())
  
      # set status to finished
      _ = self.db.Task.find_one_and_update(
          {"_id": _id}, {"$set": {"status": "finished"}}
      )
  
      # return results
      __result = {}
      for _key in _saved_result_keys:
          logging.info(
              "  result: {}={} {}".format(
                  _key, globals()[_key], type(globals()[_key])
              )
          )
          __result.update({"%s" % _key: globals()[_key]})
      _ = self.db.Task.find_one_and_update(
          {"_id": _id},
          {"$set": {"result": __result}},
          return_document=pymongo.ReturnDocument.AFTER,
      )
      logging.info(
          "[Database] Finished Task: task_name - {} sort: {} push time: {} took: {}s".format(
              task_name, sort, _datetime, time.time() - s
          )
      )
      return True
  
imports: import os
  import pickle
  import sys
  import time
  from datetime import datetime
  import numpy
  import tensorflow
  import gridfs
  import pymongo
  from tensorlayer import logging
  from tensorlayer.files import assign_weights, del_folder, exists_or_mkdir, load_hdf5_to_weights, save_weights_to_hdf5, static_graph2net
label_desc: Use image node_id 20 for calling the TensorHub obj's underlying member method code with example usage: obj.run_top_task(task_name, sort) and returns: True, False