def main(): try: with open('config.json', 'r') as f: config = json.load(f) ports = config['AddressBook'] num_ports = len(ports) except Exception as e: raise e while True: customer = client() server_id = input('Whom to connect ? 1-%d: ' % num_ports ) request = raw_input('How can we help you? --') if request == 'buy': uuid_ = uuid.uuid1() requestThread = KThread(target = customer.buyTickets, args = (ports[server_id - 1], request, uuid_)) timeout = 5 else: requestThread = KThread(target = customer.show_state, args = (ports[server_id - 1],)) timeout = 5 start_time = time.time() requestThread.start() while time.time() - start_time < timeout: if not requestThread.is_alive(): break if requestThread.is_alive(): requestThread.kill() msgP = 'Timeout! Try again' print msgP
def main(): try: with open('config.json', 'r') as f: config = json.load(f) ports = config['AddressBook'] num_ports = len(ports) except Exception as e: raise e while True: customer = client() server_id = input( 'Which datacenter do you want to connect to? 1-%d: ' % num_ports) request = raw_input('How can we help you? --') if request == 'show': requestThread = KThread(target=customer.show_state, args=(ports[server_id - 1], )) timeout = 5 elif request.split()[0] == 'change': uuid_ = uuid.uuid1() msg_split = request.split() new_config_msg = msg_split[1:] new_config = [int(item) for item in new_config_msg] print new_config requestThread = KThread(target=customer.config_change, args=(ports[server_id - 1], new_config, uuid_)) timeout = 20 else: uuid_ = uuid.uuid1() requestThread = KThread(target=customer.buyTickets, args=(ports[server_id - 1], request, uuid_)) timeout = 5 start_time = time.time() requestThread.start() while time.time() - start_time < timeout: if not requestThread.is_alive(): break if requestThread.is_alive(): print 'Timeout! Try again' requestThread.kill()