Best Python code snippet using slash
dispatcher.py
Source:dispatcher.py
...60 worker.create_corpus()61 self.token_mappings = {word: set() for word in range(self.V)}62 for worker in self.workers.values():63 for word in worker.get_uniques():64 self.token_mappings[word].add(worker.get_worker_id())65 #for worker in self.workers.values():66 # worker.create_mappings()67 @Pyro4.expose68 @Pyro4.oneway69 def remove_worker_mapping(self, word, worker_id):70 self.token_mappings[word].discard(worker_id)71 @Pyro4.expose72 def get_token_mappings(self, word):73 return list(self.token_mappings[word])74 @Pyro4.expose75 def receive_finished_token(self, token):76 self.finished_tokens[token[0]] = token[1]77 @Pyro4.expose78 @Pyro4.oneway79 def add_initial_token(self, token):80 if token[0] == 0:81 which_worker = 082 else:83 mappings = list(self.token_mappings[token[0] - 1])84 which_worker = mappings[0]85 self.workers[which_worker].receive_token(token)86 def join(self):87 while not all(worker.check_done() for worker in self.workers.values()):88 sleep(0.5)89 @Pyro4.expose90 def wait(self):91 self.join()92 print "Passed:"93 for worker in self.workers.values():94 print "Worker %i:" % worker.get_worker_id(), worker.tokens_passed()95 print96 print "Received"97 for worker in self.workers.values():98 print "Worker %i:" % worker.get_worker_id(), worker.tokens_received()99 print100 print "Dead Received"101 for worker in self.workers.values():102 print "Worker %i:" % worker.get_worker_id(), worker.get_dead_received()103 for worker in self.workers.values():104 worker.exit()105 # TODO: Get the wt, dt and zt106 return "Done"107 108 @Pyro4.expose109 def num_workers(self):110 return len(self.workers)111 @Pyro4.expose112 @Pyro4.oneway113 def exit(self):114 import os115 os._exit(0)116 def finish(self):...
worker.py
Source:worker.py
...62 e = threading.Event()63 while not e.wait(DATA_STREAM_SIMULATION_INTERVAL) and not isStopped:64 if remote_worker is not None:65 load_data_on_remote_worker()66def get_worker_id():67 try:68 worker_id = int(os.environ['WORKER_ID'])69 except:70 print('Worker id must be an integer, assigning default worker id')71 worker_id = 172 return worker_id73def get_worker_config():74 config = {}75 try:76 config = {77 "ID": get_worker_id(),78 "host": os.environ['HOST'],79 "port": int(os.environ['PORT'])80 }81 except:82 print("Check docker-compose for worker configuration parameters")83 return config84def signal_handler(sig, frame):85 print('Shutting down worker')86 global isStopped, data_stream_thread87 isStopped = False88 if data_stream_thread is not None:89 data_stream_thread.join()90 if status_thread is not None:91 status_thread.join()92 sys.exit(0)93def load_data_on_remote_worker():94 remote_worker.clear_objects()95 tensor_X, tensor_y = convert_data_to_tensor(load_sensor_data(get_worker_id()))96 remote_worker.observations = tensor_X97 remote_worker.target = tensor_y98start_status_periodically()99start_websocket_worker()100start_stream_data_simulation()...
Snowflake-remote
Source:Snowflake-remote
...17 print ''18 print 'Usage: ' + sys.argv[0] + ' [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]'19 print ''20 print 'Functions:'21 print ' i64 get_worker_id()'22 print ' i64 get_timestamp()'23 print ' i64 get_id(string useragent)'24 print ' i64 get_datacenter_id()'25 print ''26 sys.exit(0)27pp = pprint.PrettyPrinter(indent = 2)28host = 'localhost'29port = 909030uri = ''31framed = False32http = False33argi = 134if sys.argv[argi] == '-h':35 parts = sys.argv[argi+1].split(':')36 host = parts[0]37 port = int(parts[1])38 argi += 239if sys.argv[argi] == '-u':40 url = urlparse(sys.argv[argi+1])41 parts = url[1].split(':')42 host = parts[0]43 if len(parts) > 1:44 port = int(parts[1])45 else:46 port = 8047 uri = url[2]48 if url[4]:49 uri += '?%s' % url[4]50 http = True51 argi += 252if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':53 framed = True54 argi += 155cmd = sys.argv[argi]56args = sys.argv[argi+1:]57if http:58 transport = THttpClient.THttpClient(host, port, uri)59else:60 socket = TSocket.TSocket(host, port)61 if framed:62 transport = TTransport.TFramedTransport(socket)63 else:64 transport = TTransport.TBufferedTransport(socket)65protocol = TBinaryProtocol.TBinaryProtocol(transport)66client = Snowflake.Client(protocol)67transport.open()68if cmd == 'get_worker_id':69 if len(args) != 0:70 print 'get_worker_id requires 0 args'71 sys.exit(1)72 pp.pprint(client.get_worker_id())73elif cmd == 'get_timestamp':74 if len(args) != 0:75 print 'get_timestamp requires 0 args'76 sys.exit(1)77 pp.pprint(client.get_timestamp())78elif cmd == 'get_id':79 if len(args) != 1:80 print 'get_id requires 1 args'81 sys.exit(1)82 pp.pprint(client.get_id(args[0],))83elif cmd == 'get_datacenter_id':84 if len(args) != 0:85 print 'get_datacenter_id requires 0 args'86 sys.exit(1)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!