def build_workers(workers=3, *args, **kwargs): handle = do_thing(*args, **kwargs) for i in range(int(workers)): t = ThreadWorker( task=args[0][0], callback = handle.callback, workername = args[0][1], host_list = handle.hosts_list ) t.start()
# * Email : [email protected] # * Last modified : 2013-11-22 15:32 # * Filename : runworkers.py # * Description : # * *****************************************************************************/ from workers import Worker, ThreadWorker from gearman.worker import GearmanWorker def callbacks(GearmanWorker, job): json_data = job.data result = json_data print result return result for i in range(10): """ range,为开辟线程数 参数: task:任务名称 callback:函数回调的名称 workername:工人的名字(哪个IDC) daemon:是否为守护线程,默认Flase host_list:服务器的接口,list """ t = ThreadWorker(task="test",callback=callbacks,workername='TEST',daemon=False) # print dir(t.daemon) t.start()
net_type = NeuralNets.ONN if args.network_type == 1 else NeuralNets.BNN neural_network = NNetWrapper(board_size=(args.board_size, args.board_size), batch_size=args.batch_size, epochs=args.epochs, lr=args.learning_rate, dropout=args.dropout, network=net_type) if args.weights_file: neural_network.load_checkpoint(args.weights_file) evaluation_agent_class = RandomOthelloAgent evaluation_agent_arguments = dict() worker_manager = WorkerManager() worker_manager.add_worker(ThreadWorker()) if args.google_workers: assert args.google_credentials, 'Google Cloud Credentials required' assert args.google_project, 'Google Cloud Project name required' assert args.google_zone, 'Google Cloud instances zone required' assert args.google_key_filename, 'Google Cloud SSH Private key required' os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = args.google_credentials compute = googleapiclient.discovery.build('compute', 'v1') instances = gcloud.search_instances(compute, args.google_project, args.google_zone, args.google_workers_label, 'true')