def daemon_active(): """ Used to determine if the daemon is reachable to communicate """ try: rpyc.connect("localhost", 18813) return True except socket.error: return False
def handle(self, *args, **options): if options['trigger']: for s in Site.objects.all(): if not s.var: continue try: c = rpyc.connect(s.host, int(s.port), ipv6=True) c.root.command("trigger","sync",*s.var.split()) c.close() except EnvironmentError as e: if e.errno == errno.ECONNREFUSED: print >>sys.stderr,"Connecting to '%s' failed" % (s.host,) continue print_exc() except Exception: print_exc() else: print >>sys.stderr,"Connecting to '%s' succeeded" % (s.host,) sleep(10) q = Q() if options['site']: q &= Q(controller__site__name=options['site']) if options['group']: q &= Q(groups__name=options['group']) if options['controller']: q &= Q(controller__name=options['controller']) if options['feed']: q &= Q(feed__name=options['feed']) global soon if options['delay'] is not None: delay=float(options['delay']) elif options['trigger']: delay=1 else: delay=10 soon=n+timedelta(0,delay*60) sites = set() if len(args): for a in args: v = Valve.objects.get(q & Q(name=a)) if options['trigger']: sites.add(v.controller.site) self.force_one_valve(v, options) self.one_valve(v, options) else: for v in Valve.objects.filter(q).order_by("level"): if options['trigger']: sites.add(v.controller.site) self.force_one_valve(v,options) for v in Valve.objects.filter(q).order_by("level"): self.one_valve(v,options) if options['trigger']: for s in sites: c = rpyc.connect(s.host, int(s.port), ipv6=True) c.root.command("trigger","read","schedule",*s.var.split()) c.close()
def connect_slave(self,slaveID): try: conn = rpyc.connect(self.slaveAliveList[slaveID],self.port) except: print "process [%d] first time fail"%slaveID time.sleep(5) try: conn = rpyc.connect(self.slaveAliveList[slaveID],self.port) except: print "process [%d] second time fail"%slaveID raise print "slave service on ", conn.root.slaveHostname(), ' is connected. ' return conn
def main(): parser = argparse.ArgumentParser(description='Run experiments') parser.add_argument('--debug', default=False, const=True, action='store_const', help='enable debug mode') args = parser.parse_args() print(args) if args.debug: global WARMUP_TIME, MEASURE_TIME, IDLENESS log.critical("debug mode enabled") WARMUP_TIME = 0 MEASURE_TIME = 0.5 IDLENESS = 70 lxcs = [] for x in range(4): ip = str(IPv4Address("172.16.5.10")+x) print(ip) name = "perf%s" % x lxc = LXC(name=name, root=LXC_PREFIX+name, tpl=LXC_PREFIX+"/perftemplate/", addr=ip, gw="172.16.5.1", cpus=[x]) lxcs += [lxc] lxc.destroy() #lxc.create() # lxc.start() #sys.exit() # single lxc = lxcs[0] lxc.create() lxc.start() log.debug("giving VMS time to start") events = get_useful_events() time.sleep(6) rpc = rpyc.connect(lxc.addr, port=6666) RPopen = rpc.root.Popen def stat(output): cgstat(path="lxc/"+lxc.name, cpus=lxc.cpus, events=events, t=MEASURE_TIME, out=output) # TODO: hardcoded single(RPopen, outdir="/home/sources/perftest/results/u2/single", stat=stat) # double bglxc = lxcs[1] bglxc.create() bglxc.start() time.sleep(6) bgrpc = rpyc.connect(bglxc.addr, port=6666) BGPopen = bgrpc.root.Popen def stat(output): cgstat(path="lxc/"+lxc.name, cpus=lxc.cpus, events=events, t=MEASURE_TIME, out=output) double(RPopen, BGPopen, outdir="/home/sources/perftest/results/u2/double", stat=stat)
def dc_thread(id, ip, pt): global g_dc_loads g_dc_loads[id] = 0 while True: try: s = rpyc.connect(ip, int(pt)) print('Connected to ' + ip + ' on port ' + pt) except Exception: print('Could not connect to ' + ip + ' on port ' + pt) time.sleep(1) continue while True: dat = DCLoadRecords(ip) g_dc_loads[ip] = dat try: dat.networkload = s.root.get_load() dat.costs = s.root.get_cost_data() print(dat.costs) dat.bandwidthcap = s.root.get_bandwidthcap() dat.serveron = True except Exception: print('Connection to ' + ip + ', ' + pt + ' timed out.') g_dc_loads[id] = dat break g_dc_loads[ip] = dat time.sleep(INTERVAL) s.close()
def ModelUpdated(self): """Called when the system model has been updated""" # Are we a fake PLC? #log.debug("ModelUpdate... are we fake?") if not self.hardwareComm.IsFakePLC(): # No, so update the system #log.debug("We are not Fake... so update!") self.__UpdateState() # Attempt to connect to the state monitor if self.__pStateMonitor == None: try: self.__pStateMonitor = rpyc.connect("localhost", 18861) log.debug("Connection to state monitor established") self.__bStateMonitorError = False except socket.error, ex: if not self.__bStateMonitorError: log.error("Failed to connect to state monitor") self.__pStateMonitor = None self.__bStateMonitorError = True # Update the state monitor if self.__pStateMonitor != None: try: self.__pStateMonitor.root.UpdateState(self.GetStateString()) except EOFError, ex: # Catch EOFErrors in the event that the state monitor process dies log.error("Failed to update state monitor") log.error("Traceback:\r\n%s\r\n" % traceback.format_exc()) self.__pStateMonitor = None self.__bStateMonitorError = True
def connectToServer(ID=None, clientType="NONE"): ''' Try to connect to the server and launch the BG thread service ''' if not ID: ID = getpass.getuser() global server_conn global bgsrv try: server_conn = rpyc.connect(HComHoudiniUtils.readIni()["SERVER"], int(HComHoudiniUtils.readIni()["PORT"]), service=HCom_ClientService, config={"allow_pickle":True}) except Exception as e: print("ERROR: Can not connect to server: " + str(e)) return False, False else: if ID in server_conn.root.getAllClients().keys(): hou.ui.displayMessage("User ID already registered on the server") server_conn.close() return False hou.session.HCOMCLIENT = [server_conn, ID] global server_id server_id = ID bgsrv = rpyc.BgServingThread(server_conn) result = server_conn.root.registerClient(ID, clientType) if result: return ID else: return False
def request_votes(): total_votes = 0 last_index, last_term = RaftService.get_last_log_index_and_term() # TODO Run this concurrently # Suggestion: Create a separate RPC call to handle response. This RPC only requests for vote. # For now we assume that the network wont fail for peer in RaftService.peers: try: vote = False connection = rpyc.connect(peer[1], peer[2], config={"allow_public_attrs": True}) vote = connection.root.requestRPC(term=RaftService.term, candidate_id=RaftService.server_id, last_log_index=last_index, last_log_term=last_term) RaftService.logger.info("Vote received: " + str(vote)) if vote: RaftService.logger.info("Received vote from server %d for leader election, term %d" % (peer[0], RaftService.term)) total_votes = total_votes + 1 except Exception as details: #// RaftService.logger.warning("request_votes: Unable to connect to server %d" % peer[0]) # +1 to account for self-vote pass return total_votes + 1
def return_result(return_status, current_time, *args, **kwargs): return_info = kwargs['node_name'] project = return_info.split('-')[0] platname = return_info.split('-')[1] servername = return_info.split('-')[5].split('_')[1] # updates if args and current_time == None: arg = args #package_version = "%s" % str(arg[0].split('&')[0]) package_version = "%s" % arg[0] #server_status = "%s" % str(arg[0].split('&')[1]) server_status = "%s" % arg[1] put_string = "%s-%s-%s-%s-%s" % (project, servername, platname, return_status, package_version) else: # get user online if current_time: users = "%s" % args[0] #put_string = "%s-%s-%s-%s@%s" % (project, servername, platname, args,return_status, current_time) put_string = "%s-%s-%s-%s@%s" % (project, servername, platname, users, current_time) # other actions else: put_string = "%s-%s-%s-%s" % (project, servername, platname, return_status) put_string = m_encode(put_string, SECRET_KEY) try: # paramters host, port conn =rpyc.connect(SERVER, PORT) rLogin =conn.root.login("%s" % USER, "%s" % PASSWD) except Exception, e: rLogin = False return 'Connect to rpyc server error:' + str(e) sys.exit()
def module_run(request): import rpyc from cPickle import loads put_string = '' if not 'ModuleID' in request.GET: Module_Id = "" else: Module_Id = request.GET['ModuleID'] put_string+=Module_Id+"@@" if not 'hosts' in request.GET: Hosts = "" else: Hosts = request.GET['hosts'] put_string+=Hosts+"@@" if not 'sys_param_1' in request.GET: Sys_param_1 = "" else: Sys_param_1 = request.GET['sys_param_1'] put_string+=Sys_param_1+"@@" if not 'sys_param_2' in request.GET: Sys_param_2 = "" else: Sys_param_2 = request.GET['sys_param_2'] put_string+=Sys_param_2+"@@" try: conn = rpyc.connect(host='127.0.0.1', port=11511) conn.root.login('OMuser','123456') except Exception,e: logger.error('connect rpyc server error:'+str(e)) return HttpResponse('connect rpyc server error:'+str(e))
def set_colour(colour): ''' All-in-one function to request a colour change ''' connection = rpyc.connect(HOST, PORT) rgb_controller = connection.root return_value = rgb_controller.set_colour(colour) connection.close() return return_value
def start(self): cgroups = [] rpcs = [] self.stop() # just to be sure # START KVMS info("starting kvms") for n in self.cpus: cgkvm = CGKVM(n) time.sleep(0.5) # interval between launching # WAIT TILL THEY START UP idleness = self.idfactor * (len(self.cpus) + 2) self.log.info("waiting for instances, expected idleness is <%s" % idleness) time.sleep(15) wait_idleness(idleness) # CREATE RPC CONNECTIONS info("making connections") for cpu in self.cpus: host = "172.16.5.%s" % (cpu + 1) print("connecting to", host) rpcs += [rpyc.connect(host, port=6666)] for i, cg in enumerate(cgroups): instance = Instance(cg=cg, rpc=rpcs[i], Popen=rpcs[i].root.Popen)
def __init__(self): self.transmitting = False self.processed = True self.terminated = False self.c = rpyc.connect(ADDR, PORT) self.c.root.configureVideoStream(TCP_IP, TCP_PORT) self.image = None
def __new__(cls): if not cls._instance or not not cls._instance.root: try: cls._instance = rpyc.connect(get_worker_host(), get_worker_port()) except: cls._instance = None return cls._instance
def connect(bot): global sv_con # print 'connecting to bot' BorkedbotClientService.bot = bot sv_con = rpyc.connect('localhost', 29389, service=BorkedbotClientService, config={'allow_all_attrs': True, 'exposed_prefix': ''}) sv_con.root.init_bot(bot)
def commandLineProcess(scanConf): import scanner.logSetup import rpyc scanner.logSetup.initLogging() if not os.path.exists(scanConf.sourcePath): print("ERROR: Source file does not exist!") return if not os.path.isfile(scanConf.sourcePath): print("ERROR: Source is not a file!") return if scanConf.noContext: scanContext = None else: scanContext = [os.path.split(scanConf.sourcePath)] remote = rpyc.connect("localhost", 12345) status, bestMatch, intersections = remote.root.processDownload( scanConf.sourcePath, pathFilter=scanContext, distance=6, moveToPath=None, locked=True) print("Processed archive. Return status '%s'", status) if bestMatch: print("Matching archive '%s'", bestMatch) return status, bestMatch, intersections
def module_run(req): import rpyc put_string = "" if not "ModuleID" in req.GET.get(): Module_Id = "" else: Module_Id = req.GET.get("ModuleID") put_string += Module_Id + "@@" if not "hosts" in req.GET.get(): Hosts = "" else: Hosts = req.GET.get("hosts") put_string = Hosts + "@@" """ module extend params recive """ if not "sys_param_1" in req.GET.get(): Sys_param_1 = "" else: Sys_param_1 = req.GET.get("sys_param_1") put_string = Sys_param_1 + "@@" if not "sys_param_2" in req.GET.get(): Sys_param_2 = "" else: Sys_param_2 = req.GET.get("sys_param_1") put_string = Sys_param_2 + "@@" try: conn = rpyc.connect("127.0.0.1", 11511) conn.root.login("sean", "htbenet100") except Exception, e: logger.error("connect to rpyc server failed" + str(e)) return HttpResponse("connect to rpyc server failed" + str(e))
def client(): import rpyc c = rpyc.connect("localhost", 18861) sender = c.root.SsdpSender() listen = SsdpListen(sender) listen.open() listen.run()
def run_training(head_host, head_port, debug_out=None): """Main worker training routine (creates the Seq2SeqTrainingService and connects it to the head. @param head_host: hostname of the head @param head_port: head port number @param debug_out: path to the debugging output file (debug output discarded if None) """ # setup debugging output, if applicable if debug_out is not None: set_debug_stream(file_stream(debug_out, mode='w')) # start the server (in the background) log_info('Creating training server...') server = ThreadPoolServer(service=Seq2SeqTrainingService, nbThreads=1) server_thread = Thread(target=server.start) server_thread.start() my_host = socket.getfqdn() log_info('Worker server created at %s:%d. Connecting to head at %s:%d...' % (my_host, server.port, head_host, head_port)) # notify main about this server conn = connect(head_host, head_port, config={'allow_pickle': True}) conn.root.register_worker(my_host, server.port) conn.close() log_info('Worker is registered with the head.') # now serve until we're killed (the server thread will continue to run) server_thread.join()
def __init__(self, rpyc_hosts, thrill_hosts): # connect to rpyc servers self._conn = [rpyc.connect(*hp) for hp in rpyc_hosts] # set up background serving threads self._bgthr = [rpyc.BgServingThread(conn) for conn in self._conn] # make async objects to create Thrill contexts anetrefs = [rpyc.async(conn.root.Create) for conn in self._conn]
def module_run(request): import rpyc from cPickle import loads put_string="" if not 'ModuleID' in request.GET: Module_Id="" else: Module_Id=request.GET['ModuleID'] put_string+=Module_Id+"@@" if not 'hosts' in request.GET: Hosts="" else: Hosts=request.GET['hosts'] put_string+=Hosts+"@@" if not 'sys_param_1' in request.GET: Sys_param_1="" else: Sys_param_1=request.GET['sys_param_1'] put_string+=Sys_param_1+"@@" if not 'sys_param_2' in request.GET: Sys_param_2="" else: Sys_param_2=request.GET['sys_param_2'] put_string+=Sys_param_2+"@@" try: conn=rpyc.connect('172.16.28.246',11511) conn.root.login('OMuser','KJS23o4ij09gHF734iuhsdfhkGYSihoiwhj38u4h') except Exception,e: logger.error('connect rpyc server error:'+str(e)) return HttpResponse('connect rpyc server error:'+str(e))
def __init__(self): """ Initialises the whole environment and establishes connection """ self.mgmt_node = '' self.clients = self.nodes = self.peers = self.gm_nodes = [] self.gm_peers = self.gs_nodes = self.gs_peers = [] self.number_nodes = self.number_peers = self.number_gm_nodes = 0 self.number_gm_peers = self.number_gs_nodes = self.number_gs_peers = 0 self.number_clients = self.number_servers = self.number_masters = 0 self.number_slaves =0 if 'MGMT_NODE' in os.environ: self.mgmt_node = os.environ['MGMT_NODE'] if 'NODES' in os.environ: self.nodes = os.environ['NODES'].split(' ') if 'PEERS' in os.environ: self.peers = os.environ['PEERS'].split(' ') if 'CLIENTS' in os.environ: self.clients = os.environ['CLIENTS'].split(' ') if 'GM_NODES' in os.environ: self.gm_nodes = os.environ['GM_NODES'].split(' ') if 'GM_PEERS' in os.environ: self.gm_peers = os.environ['GM_PEERS'].split(' ') if 'GS_NODES' in os.environ: self.gs_nodes = os.environ['GS_NODES'].split(' ') if 'GS_PEERS' in os.environ: self.gs_peers = os.environ['GS_PEERS'].split(' ') self.number_nodes = len(self.nodes) self.number_peers = len(self.peers) self.number_clients = len(self.clients) self.number_gm_nodes = len(self.gm_nodes) self.number_gm_peers = len(self.gm_peers) self.number_gs_nodes = len(self.gs_nodes) self.number_gs_peers = len(self.gs_peers) self.servers = self.nodes + self.peers + self.gm_nodes + self.gm_peers \ + self.gs_nodes + self.gs_peers self.all_nodes = self.nodes + self.peers + self.clients + self.gm_nodes\ + self.gm_peers + self.gs_nodes + self.gs_peers self.connection_handles = {} for node in self.all_nodes: c0 = rpyc.connect(node, 18861) async_object = rpyc.async(c0.root.run) self.connection_handles[node] = ( c0, async_object) client_logfile = "/var/log/tests/client_rpyc.log" client_logdir = os.path.dirname(client_logfile) #Check if the log directory exits, if not create it if not os.path.exists(client_logdir): os.makedirs(client_logdir) self.logger = logging.getLogger('rpyc_client') self.lhndlr = logging.FileHandler(client_logfile) formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s %(message)s') self.lhndlr.setFormatter(formatter) self.logger.addHandler(self.lhndlr) self.logger.setLevel(logging.DEBUG)
def refresh(request): """ Clears the playlist database and rebuilds it from the homespot server. """ Playlist.objects.all().delete() c = rpyc.connect("localhost", 10223, config = {"allow_public_attrs": True}) hs = c.root.homespot() pc = hs.session.playlist_container() playlists = len(pc) homespot = [] for pl in xrange(playlists): songs = len(pc[pl]) playlist = Playlist.objects.create(name=pc[pl].name()) playlist.save() sngs = [] for song in xrange(songs-1): try: s = pc[pl][song] if s.is_loaded() and s.is_available(): artists = u", ".join([unicode(artist.name(), "utf-8") for artist in s.artists(None)]) name = unicode(s.name(), "utf-8") album = unicode(s.album().name(), "utf-8") Track.objects.create(name=name,artists=artists,album=album,playlist=playlist) except: import traceback traceback.print_exc() print "hmm: %s %s " % (playlist, song) return HttpResponse("OK")
def connect_to_live(scr, args): conn = None while conn == None: scr.clear() center_addstr(scr, 0, 'Connecting to Ableton Live...', curses.color_pair(colors.connecting)) scr.refresh() try: conn = rpyc.connect(args.host, args.port) except IOError: center_addstr(scr, 0, 'Connection to Ableton Live failed', curses.color_pair(colors.error)) center_addstr(scr, 1, 'Press any key to retry') scr.refresh() curses.flushinp() scr.getch() scr.clear() live = conn.root.Live.Application.get_application() center_addstr(scr, 0, 'Connected to to Ableton Live %s.%s.%s' % (live.get_major_version(), live.get_minor_version(), live.get_bugfix_version()), curses.color_pair(colors.success)) return conn
def __init__(self, host='127.0.0.1', port=17744): try: self.conn = rpyc.connect(host, port) self.live = self.conn.root.Live.Application.get_application() self.song = self.live.get_document() except IOError: print "Could not connect to Ableton, is it running?"
def naxos(): #Keypair generation #BOB# domain, bob_pub_key, bob_priv_key = ec.get_keypair() #connecting to a server conn = rpyc.connect("localhost", 18861, config = {"allow_all_attrs" : True}) c = conn.root alice_pub_key = c.exchange_pubkey(bob_pub_key) print 'Alice pub key', alice_pub_key bob_esk = random.getrandbits(32) #32 bitowy ciag losowy G = domain.P #nasz publiczny punkt na krzywej #exch_bob H1(esk_B, sk_B) exch_bob = hashfun.sha(hashfun.concat(bob_esk, bob_priv_key.a)) exch_alice = c.exchange(G * exch_bob) S0 = alice_pub_key.Q * exch_bob #punkt S1 = (exch_alice) * bob_priv_key.a #punkt S2 = (exch_alice) * exch_bob session_key = hashfun.sha(hashfun.concat(S0.x.n, S1.x.n, S2.x.n)) print 'Session key:', session_key #AES PART print "Encoding AES message [Sample message]..." ac = AESCipher(session_key) enc = ac.encrypt('Sample message') print "Sending encrypted message [%s]..." % enc c.decrypt(enc)
def set_heat_state(on): try: device_conn = rpyc.connect(Config.service_config["device_service_address"], Config.service_config["device_service_port"]) try: device_conn.root.set_heater_state(on) device_conn.close() ReactiveControl.current_heat_state = on if on: ReactiveControl.current_air_speed = Config.control_config["max_fan_speed"] else: ReactiveControl.current_air_speed = 0 Config.logger.info("[Set Heater State][%s]" % str(on)) return True except Exception, e: Config.logger.warning("Error sending heater state to %s:%s" % (Config.service_config["device_service_address"], Config.service_config["device_service_port"])) Config.logger.error(e) device_conn.close() return False except Exception, e: Config.logger.warning("Error connecting to %s:%s" % (Config.service_config["device_service_address"], Config.service_config["device_service_port"])) Config.logger.error(e) return False
def set_cool_state(on, speed): relative_speed = float(speed) / Config.control_config["max_fan_speed"] try: device_conn = rpyc.connect(Config.service_config["device_service_address"], Config.service_config["device_service_port"]) try: device_conn.root.set_fan_state(on, relative_speed) device_conn.close() ReactiveControl.current_cool_state = on ReactiveControl.current_air_speed = float(speed) Config.logger.info("[Set Fan State][%s]" % str(on)) Config.logger.info("[Set Fan Speed][Absolute][%s][Relative][%s]" % (str(float(speed)), str(relative_speed))) return True except Exception, e: Config.logger.warning("Error sending fan state to %s:%s" % (Config.service_config["device_service_address"], Config.service_config["device_service_port"])) Config.logger.error(e) device_conn.close() return False except Exception, e: Config.logger.warning("Error connecting to %s:%s" % (Config.service_config["device_service_address"], Config.service_config["device_service_port"])) Config.logger.error(e) return False
def diffie_hellman(): #BOB# domain, bob_pub_key, bob_priv_key = ec.get_keypair() conn = rpyc.connect("localhost", 18861, config = {"allow_public_attrs" : True}) c = conn.root #Agree upon a public key c.send_pub_key(bob_pub_key) alice_pub_key = c.get_pub_key() print "Alice:\n", alice_pub_key secret_bob = bob_priv_key.a * alice_pub_key.Q print "Sharing secret..." secret_alice = c.share_secret(secret_bob) print "Secrets:\nAlice: %s\nBob %s\n" % (secret_alice, secret_bob) print "Encoding AES message [Sample message]..." ac = AESCipher(secret_bob.x) enc = ac.encrypt('Sample message') print "Sending encrypted message [%s]..." % enc c.decrypt(enc)
def exposed_config_changeRPC(self, list_of_config_changes, client_id): new_config_change_success = False RaftService.logger.info("Received Configuration Change Request from client %s" % client_id) if RaftService.server_id != RaftService.leader_id: try: RaftService.logger.info("Redirecting the request to Leader %s" % RaftService.server_id) (ip, port) = RaftService.config_reader.get_leaders_port_ip(RaftService.leader_id, RaftService.peers) connection = rpyc.connect(ip, port, config={"allow_public_attrs": True}) new_config_change_success = connection.root.exposed_config_change_leaderRPC(list_of_config_changes, client_id) except Exception as details: RaftService.logger.info(details) else: entry = (JOINT_CONFIGURATION, list_of_config_changes) ### Apply Joint Configuration self.run_config_change(entry) joint_config_change_success = self.append_entries(entry, client_id) if joint_config_change_success: # Joint consensus is running. So start new config now ###Apply new configuration self.run_config_change((NEW_CONFIGURATION,list_of_config_changes)) new_config_change_success = self.append_entries((NEW_CONFIGURATION,list_of_config_changes), client_id) if new_config_change_success: RaftService.trigger_next_heartbeat() RaftService.logger.info("Successfully changed the configuration of the system.") if RaftService.server_id == RaftService.leader_id: reducted_peers = list() for peer in RaftService.peers: flag = True for remove_id in RaftService.peers_to_remove: if peer[0] == remove_id: flag = False if flag: reducted_peers.append(peer) RaftService.peers_old = reducted_peers RaftService.peers = reducted_peers RaftService.peers_to_remove = list() if RaftService.server_id == RaftService.leader_id: self.config_reader.update_config_file(RaftService.server_id, RaftService.total_nodes, RaftService.majority_criteria,RaftService.peers) if RaftService.should_i_die and RaftService.server_id == RaftService.leader_id: RaftService.logger.info("Stepping down as I am not part of new config") #os._exit(0) RaftService.start_deathbeat_timer() else: RaftService.logger.info("Couldn't change the configuration of system to new config.") else: RaftService.logger.info("Couldn't change the configuration of the system to joint config.") return new_config_change_success
import rpyc import socket from constRPYC import * from rpyc.utils.server import ThreadedServer class DBList(rpyc.Service): value = [] def exposed_append(self, data): self.value = self.value + [data] print("Appended value = ", data) return self.value def exposed_value(self): return self.value def exposed_delete(self, data): if data in self.value: print("Deleted value = " + data) self.value.remove(data) return self.value if __name__ == "__main__": server = ThreadedServer(DBList, port=20202) conn_dir = rpyc.connect(DIR_SERVER, DIR_PORT) my_address = socket.gethostbyname(socket.gethostname()) print(conn_dir.root.exposed_unregister("DBList")) print(conn_dir.root.exposed_register("DBList", my_address, 20202)) server.start()
sys.exit() # initialize a StatsManager sm = StatsManager(conf) # initialize a CacheManager cm = CacheManager(conf) # word_forms service # rpyc client import sys import rpyc searchExtensionConfig = conf.getExtensionConfig("space.colabo.search_extension") if conf.isExtensionActive("space.colabo.search_extension"): rpcConn = rpyc.connect(searchExtensionConfig['host'], searchExtensionConfig['port']) rpcService = rpcConn.root colaboFlowAuditConfig = conf.getExtensionConfig("space.colabo.flow.audit") if conf.isExtensionActive("space.colabo.flow.audit"): import uuid # from colabo.flow.audit import ColaboFlowAudit, audit_pb2 from colabo.flow.audit import audit_pb2 from colabo.flow.audit import ColaboFlowAudit gRpcUrl = colaboFlowAuditConfig['host']+':'+str(colaboFlowAuditConfig['port']) # https://docs.python.org/2/library/uuid.html flowInstanceId = str(uuid.uuid1()) cfAuditRequestDefualt = audit_pb2.SubmitAuditRequest( bpmn_type='activity', bpmn_subtype='task',
def main(): pygame.mixer.pre_init(44100, 16, 2, 4096) pygame.mixer.__PYGAMEinit__ pygame.init() relogio = pygame.time.Clock() campo2 = 620, 261 #Movimentação dir = [620 / 31, 0] esq = [-620 / 31, 0] up = [0, -261 / 13] down = [0, 261 / 13] #Tela e Campo screen = pygame.display.set_mode(campo2) pygame.display.set_caption("PoliciaLadrao") black = 0, 0, 0 campo2 = pygame.image.load("images\\campo2.png") camporect = campo2.get_rect().move([0, 0]) #Tela de Vitoria e Derrota lose = Objetos.lose() win = Objetos.win2() #Posição inicial do jogador #trocar para a chamada ao servidor que irá fornecer #pos = a posicao usada para desenhar na tela #p = posicao na matrix do campo para verificacao da movimentacao x1 = 620 / 31 y1 = 261 / 13 #Campo em matriz para criar as paredes internas. campo = np.zeros((13, 31)) campo[2::2, 2::2] = 1 campo[2, 3] = campo[2, 19] = campo[2, 27] = 1 campo[1, 8] = campo[3, 22] = campo[5, 14] = campo[5, 20] = campo[11, 12] = 1 campo[4, 3] = campo[4, 13] = campo[4, 27] = 1 campo[6, 1] = campo[6, 7] = campo[6, 23] = campo[6, 29] = 1 campo[10, 1] = campo[10, 9] = campo[10, 13] = campo[10, 25] = campo[10, 29] = 1 campo[2, 1] = campo[2, 9] = campo[4, 23] = campo[4, 29] = campo[5, 16] = campo[6, 11] = 2 campo[7, 4] = campo[9, 18] = campo[10, 3] = campo[10, 11] = campo[10, 27] = 2 #Criacao do jogador e dos grupos #deverá ser feita no servidor #e o jogador recebera o seu sprite #e todos os grupos ladrao = pygame.image.load("images\\ladrao.png") policia = pygame.image.load("images\\pol.png") moedas = pygame.sprite.Group() pos_xMoeda = [x1, x1 * 29, x1 * 18, x1 * 13, x1 * 10, x1 * 24, x1, x1 * 10] pos_yMoeda = [y1 * 11, y1, y1 * 7, y1 * 11, y1 * 3, y1 * 5, y1 * 7, y1 * 9] for i in range(0, 7): moeda = Objetos.moeda(pos_xMoeda[i], pos_yMoeda[i]) moedas.add(moeda) #Contador de moedas e condicao para fim #o contador sera guardado no servidor cont = 0 #repeticao das teclas #em mls (pelo menos o segundo) conn = rpyc.connect("localhost", 18861) indole = conn.root.getIndole() indice = conn.root.getIndice() pos_x = conn.root.pos_x[indice] pos_y = conn.root.pos_y[indice] px = conn.root.x[indice] py = conn.root.y[indice] if indole == 'ladrao': jog1 = Objetos.ladrao(pos_x, pos_y) pygame.key.set_repeat(150) else: jog1 = Objetos.policia(pos_x, pos_y) pygame.key.set_repeat(50) conn.root.getCredenciais(jog1.rect, indole) #sons do jogo ncont = ["nada", "one", "two", "three", "four", "five"] you_sound = pygame.mixer.Sound("sounds\you.wav") win_sound = pygame.mixer.Sound("sounds\win.wav") lose_sound = pygame.mixer.Sound("sounds\lose.wav") soundtrack = 'sounds\open_stage.mp3' pygame.mixer_music.load(soundtrack) fim = conn.root.getFim() start_music = True fim1 = False winc = 3 while not fim and not fim1: if start_music: pygame.mixer_music.set_volume(0.05) pygame.mixer_music.play(-1) start_music = False for event in pygame.event.get(): pygame.key.get_repeat() if event.type == pygame.QUIT: fim1 = True pygame.mixer_music.pause() if indole == 'ladrao': winc = 0 else: winc = 1 if event.type == pygame.KEYDOWN: if (indole == 'ladrao'): if event.key == pygame.K_UP and not ( pos_y - 261 / 13) <= 0 and not blockl( px, py - 1, campo): jog1.rect = jog1.rect.move(up) py = py - 1 pos_y = pos_y - 261 / 13 conn.root.putJogador(indice, jog1.rect) if event.key == pygame.K_DOWN and not ( pos_y + 261 / 13 > 261 - (2 * 261 / 13)) and not blockl(px, py + 1, campo): jog1.rect = jog1.rect.move(down) py = py + 1 pos_y = pos_y + 261 / 13 conn.root.putJogador(indice, jog1.rect) if event.key == pygame.K_RIGHT and not ( pos_x >= 620 - (2 * 620 / 31)) and not blockl(px + 1, py, campo): jog1.rect = jog1.rect.move(dir) px = px + 1 pos_x = pos_x + 620 / 31 conn.root.putJogador(indice, jog1.rect) if event.key == pygame.K_LEFT and not ( pos_x - 620 / 31 < 620 / 31) and not blockl( px - 1, py, campo): jog1.rect = jog1.rect.move(esq) px = px - 1 pos_x = pos_x - 620 / 31 conn.root.putJogador(indice, jog1.rect) else: if event.key == pygame.K_UP and not ( pos_y - 261 / 13) <= 0 and not block( px, py - 1, campo): jog1.rect = jog1.rect.move(up) py = py - 1 pos_y = pos_y - 261 / 13 conn.root.putJogador(indice, jog1.rect) if event.key == pygame.K_DOWN and not ( pos_y + 261 / 13 > 261 - (2 * 261 / 13)) and not block(px, py + 1, campo): jog1.rect = jog1.rect.move(down) py = py + 1 pos_y = pos_y + 261 / 13 conn.root.putJogador(indice, jog1.rect) if event.key == pygame.K_RIGHT and not ( pos_x >= 620 - (2 * 620 / 31)) and not block(px + 1, py, campo): jog1.rect = jog1.rect.move(dir) px = px + 1 pos_x = pos_x + 620 / 31 conn.root.putJogador(indice, jog1.rect) if event.key == pygame.K_LEFT and not ( pos_x - 620 / 31 < 620 / 31) and not block( px - 1, py, campo): jog1.rect = jog1.rect.move(esq) px = px - 1 pos_x = pos_x - 620 / 31 conn.root.putJogador(indice, jog1.rect) #Verifica se o jogador passou por uma moeda #O servidor tem q fazer isso verificando #se algum ladrao passou por moeda aux = conn.root.Killmoeda for moeda in moedas: if (moeda.rect == aux): moeda.kill() cont += 1 son = pygame.mixer.Sound("sounds\\" + ncont[cont] + ".wav") son.set_volume(0.7) son.play() for moeda in moedas: if pygame.sprite.collide_rect(jog1, moeda) and indole == 'ladrao': moeda.kill() cont += 1 son = pygame.mixer.Sound("sounds\\" + ncont[cont] + ".wav") son.set_volume(0.7) son.play() conn.root.setKillmoeda(moeda.rect) conn.root.cont() #Verifica se algum larao colidiu com #algum policial joga = conn.root.getJogadores() minha = joga[indice] if (indole == 'ladrao'): for jog in joga: if jog['posicao'] == minha['posicao'] and jog[ 'indole'] == 'policia': conn.root.delJogador(indice) fim1 = True #Desenho da tela screen.fill(black) screen.blit(campo2, camporect) for moeda in moedas: screen.blit(moeda.image, moeda.rect) screen.blit(jog1.image, jog1.rect) jogadores = conn.root.getJogadores() for jogador in jogadores: if (jogador['vivo']): if (jogador['indole'] == 'ladrao'): screen.blit(ladrao, jogador['posicao']) else: screen.blit(policia, jogador['posicao']) pygame.display.flip() relogio.tick(30) fim = conn.root.getFim() if fim: pygame.mixer_music.pause() winb = conn.root.win confirm = False c_sound = 0 while (not confirm): for event in pygame.event.get(): if event.type == pygame.QUIT: confirm = True #if event.type == pygame.KEYDOWN: # confirm = True screen.fill(black) screen.blit(campo2, camporect) for jogador in jogadores: if (jogador['vivo']): if (jogador['indole'] == 'ladrao'): screen.blit(jog1.image, jogador['posicao']) else: screen.blit(policia, jogador['posicao']) if indole == 'ladrao': if (winb == 0) or (winc == 0): screen.blit(lose.image, lose.rect) pygame.display.flip() if c_sound == 0: c_sound += 1 time.sleep(1) you_sound.play(0) time.sleep(0.7) lose_sound.play(0) else: screen.blit(win.image, win.rect) pygame.display.flip() if c_sound == 0: c_sound += 1 time.sleep(1) you_sound.play(0) time.sleep(0.7) win_sound.play(0) else: if winb == 1 or winc == 1: screen.blit(lose.image, lose.rect) pygame.display.flip() if c_sound == 0: c_sound += 1 time.sleep(1) you_sound.play(0) time.sleep(0.7) lose_sound.play(0) else: screen.blit(win.image, win.rect) pygame.display.flip() if c_sound == 0: c_sound += 1 time.sleep(1) you_sound.play(0) time.sleep(0.7) win_sound.play(0) pygame.display.flip() #pygame.quit() print(cont)
import time import rpyc #============================================================================== # GLOBAL VARS #============================================================================== conn = rpyc.connect("localhost", 50051) GET_STR_PROMPT = ('Please insert string to operate:\n') # All options; keys are numbers, sub dictionary contains titles and functions (via lambda) OPTIONS = { '1': { 'title': 'Upper', 'function': (lambda string: conn.root.Upper(string)) }, '2': { 'title': 'Lower', 'function': (lambda string: conn.root.Lower(string)) }, '3': { 'title': 'Capitalize', 'function': (lambda string: conn.root.Proper(string)) } } #============================================================================== # MAIN #============================================================================== def run():
import rpyc import sys if len(sys.argv) == 2: temp = sys.argv[1] else: temp = "localhost" c = rpyc.connect(temp, port=18863) def downl(bindata, fname): fc = open(fname, "wb") fc.write(bindata) fc.close print "Download Complete!" def printlist(filename): print filename bgsrv = rpyc.BgServingThread(c) name = raw_input("Enter Your Name:") while True: cmd = raw_input("Enter your command:") if cmd == 'list':
def __init__(self): try: self.rpyc_client = rpyc.connect("localhost", 18813) except socket.error: raise Exception("Connection refused. Is the daemon running?")
import rpyc from server_list import * my_name = 'CalcServer' my_ip = '172.31.16.204' my_port = 4010 c = rpyc.connect("172.31.91.81", 4001) registrado = c.root.exposed_register(my_name, my_ip, my_port) if registrado: var = input("Deseja iniciar o servidor? Sim ou Não: ") if var.capitalize() == 'Sim': print('Server Startado') from rpyc.utils.server import ThreadedServer t = ThreadedServer(MyServer, port=4010, protocol_config={ 'allow_public_attrs': True, }) print("O servidor CalcServer foi iniciado e está executando") print("Aguardando conexões...") t.start() else: print("Ok!")
import rpyc conn = rpyc.connect("localhost", 18861) print(conn.root) subobject = conn.root.get_sub_object() print(type(subobject)) print(subobject.method1())
def client(): config = {'allow_public_attrs': True} cm = rpyc.connect('localhost', 18861, config=config) # The player chooses a location. def choose(b, k, startTime): # Variables 'n stuff. letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8'] # Loop in case of invalid entry. while True: chosen = input('Escolha o quadrado (ex. E4) ou marque caso ache que exista bomba (ex. mE4): ').lower() # Checks for valid square. if len(chosen) == 3 and chosen[0] == 'm' and chosen[1] in letters and chosen[2] in numbers: c, r = (ord(chosen[1])) - 97, int(chosen[2]) cm.root.marker(r, c, k) play(b, k, startTime) break elif len(chosen) == 2 and chosen[0] in letters and chosen[1] in numbers: return (ord(chosen[0])) - 97, int(chosen[1]) else: choose(b, k, startTime) # The majority of the gameplay happens here. def printBoard(b): replit.clear() print(' A B C D E F G H I') print(' ╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗') for r in range(0, 9): print(r, '║', cm.root.l(r, 0, b), '║', cm.root.l(r, 1, b), '║', cm.root.l(r, 2, b), '║', cm.root.l(r, 3, b), '║', cm.root.l(r, 4, b), '║', cm.root.l(r, 5, b), '║', cm.root.l(r, 6, b), '║', cm.root.l(r, 7, b), '║', cm.root.l(r, 8, b), '║') if not r == 8: print(' ╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣') print(' ╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝') def play(b, k, startTime): # Player chooses square. c, r = choose(b, k, startTime) # Gets the value at that location. v = cm.root.l(r, c, b) # If you hit a bomb, it ends the game. if v == '*': printBoard(b) print('Você Perdeu!') # Print timer result. print('Tempo: ' + str(round(time.time() - startTime)) + 's') # Offer to play again. playAgain = input('Jogar Novamente? (Y/N): ').lower() if playAgain == 'y': replit.clear() reset() else: quit() # Puts that value into the known grid (k). k[r][c] = v # Runs checkZeros() if that value is a 0. if v == 0: cm.root.checkZeros(k, b, r, c) printBoard(k) # Checks to see if you have won. squaresLeft = 0 for x in range(0, 9): row = k[x] squaresLeft += row.count(' ') squaresLeft += row.count('⚐') if squaresLeft == 10: printBoard(b) print('Voce Venceu!') # Print timer result. print('Tempo: ' + str(round(time.time() - startTime)) + 's') # Offer to play again. playAgain = input('Jogar Novamente? (Y/N): ') playAgain = playAgain.lower() if playAgain == 'y': replit.clear() reset() else: quit() # Repeats! play(b, k, startTime) print() cprint('Bem-vindo ao Game Campos Minado', 'red') cprint('=============================', 'red') print() print('Espero que goste dessa aventura') # Sets up the game. def reset(): print(''' MENU ========= -> Para saber instruções, digite 'I' -> Para jogar imediatamente, digite 'P' ''' ) choice = input('Digite: ').upper() if choice == 'I': replit.clear() # Prints instructions. print(open('instructions.txt', 'r').read()) input('Aperte [enter] para jogar!. ') elif choice != 'P': replit.clear() reset() # The solution grid. b = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] for n in range(0, 10): cm.root.placeBomb(b) for r in range(0, 9): for c in range(0, 9): value = cm.root.l(r, c, b) if value == '*': cm.root.updateValues(r, c, b) # Sets the variable k to a grid of blank spaces, because nothing is yet known about the grid. k = [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']] printBoard(k) # Start timer startTime = time.time() # The game begins! play(b, k, startTime) reset()
def rpyc_root_fn(): return rpyc.connect(rpyc_host, 8064, config={ "sync_request_timeout": 600 }).root
def delete_from_storage(block_uuid, storage): addr, port = storage con = rpyc.connect(addr, port=port) ss = con.root.Storage() return ss.delete(block_uuid)
def read_from_storage(block_uuid, storage): addr, port = storage con = rpyc.connect(addr, port=port) ss = con.root.Storage() return ss.pull(block_uuid)
def __init__(self): self.semaphore = rpyc.connect("localhost", 18812, config={'sync_request_timeout': None})
import rpyc turismo = rpyc.connect('localhost', 35000) hotel = rpyc.connect('localhost', 35001) restaurante = rpyc.connect('localhost', 35002) area = rpyc.connect('localhost', 35003) while True: cidade = input('Cidade para consulta (e para sair): ') if cidade == 'e': break resultadoTurismo = turismo.root.pesquisaTurismo(cidade) resultadoHotel = hotel.root.pesquisaHotel(cidade) resultadoRestaurante = restaurante.root.pesquisaRestaurante(cidade) resultadoAerea = area.root.pesquisaAerea(cidade) print(resultadoTurismo) print(resultadoHotel) print(resultadoRestaurante) print(resultadoAerea)
def read_from_minion(block_uuid, minion): host, port = minion con = rpyc.connect(host, port=port) minion = con.root.Minion() return minion.get(block_uuid)
def send_to_minion(block_uuid, data, minionInfo): host, port = minionInfo con = rpyc.connect(host, port=port) minion = con.root.Minion() minion.put(block_uuid, data)
import rpyc conn = rpyc.connect("localhost", 1337) conn.root.print("OK")
def connect(host='localhost', port=12345): """ Connect to SIP """ global connection_ connection_ = rpyc.connect(host, port)
def index_texts(self, rebuild=False, cache=False, cores: int = 0): """ Vectorize text files (needed for semantic search) """ # TODO: index images # TODO: auto index on file addition (import) from .vectorizer import TextVectorizer, extract_clean_text, get_text_documents print("Vectorizing text documents...") remote = True if remote: try: rpc = rpyc.connect("localhost", 18861) rpc._config["sync_request_timeout"] = None # Disable timeout print("Connected to DaemonService successfully") except ConnectionRefusedError: print( "DaemonService connection failed, falling back to local execution..." ) remote = False if cache: print("Caching cleaned texts (database will grow big)") if rebuild: print("Rebuilding texts index") file_paths = self.db.get_vectorized_file_paths() else: file_paths = self.db.get_unvectorized_file_paths() i = 0 compatible_files = get_text_documents(file_paths, verbose=True) min_words = 5 min_word_length = 4 args = [] for file_path, file_type in compatible_files: args.append( (file_path, file_type, cache, min_words, min_word_length)) inference_tuples = [] # Preprocess using multi-processing (default uses all available cores) if cores <= 0: n_cores = os.cpu_count() else: n_cores = cores pool = Pool(processes=n_cores) print(f"Preprocessing texts using {n_cores} cores...") with tqdm(total=len(compatible_files)) as t: for file_path, sentences in pool.imap_unordered( extract_clean_text, args): t.update(1) if sentences: inference_tuples.append((file_path, sentences)) print(f"Cleaned {len(inference_tuples)} text doc/s successfully") print("Starting inference...") # Compute embeddings if not remote: vectorizer = TextVectorizer(verbose=True) for file_path, sentences in tqdm(inference_tuples): if remote: document_vector = json.loads( rpc.root.compute_text_embedding(json.dumps(sentences))) else: document_vector = vectorizer.compute_text_embedding(sentences) if (document_vector is not None and type(document_vector) is list and len(document_vector) > 0): self.db.add_file_embedding_vector(file_path, json.dumps(document_vector)) self.db.add_text(file_path, ". ".join([" ".join(s) for s in sentences])) self.db.conn.commit() i += 1 else: print(type(document_vector)) self.db.add_file_embedding_vector(file_path, json.dumps([])) self.db.conn.commit() print("Failed to parse file - skipping:", file_path) print(f"Vectorized {str(i)} file/s successfully") print("Updating index...") if remote: rpc.root.update_text_index() else: vectorizer.update_index()
def rpc(dest, cmd, args): c = rpyc.connect(dest, RPC_PORT) s = 'c.root.%s(*args)' % cmd out = copy.deepcopy(eval(s)) c.close() return out
filetable = pickle.load(fl) ports = list(filetable.keys()) map_file = input('Enter the location of the map file\n') if not os.path.isfile(map_file): print('No such file exists\n') sys.exit() with open(map_file, 'r') as f1: content = f1.read() reduce_file = input('Enter the location of the reduce file\n') if not os.path.isfile(reduce_file): print('No such file exists\n') sys.exit() target_file = input( 'Enter the name of the file on which you want to run Map Reduce\n') if not os.path.isfile(target_file): print('No such file exists\n') sys.exit() target_folder = ''.join(target_file.split('/')[-1].split('.')[:-1]) print(target_folder) for port, folders in filetable.items(): if target_folder in filetable[port].keys(): # location=str(port)+'/'+target_folder+'/' c = rpyc.connect('localhost', port=port) print('File is present in:\n' + str(port)) interm_output = str(c.root.submit_mr_job(content, target_folder)) int_med_file_loc = os.path.expanduser('~') + '/Desktop/interm_output.txt' with open(int_med_file_loc, 'w') as inter_med: inter_med.write(interm_output) print(subprocess.getoutput('python %s %s' % (reduce_file, int_med_file_loc)))
import rpyc import sys try: conn = rpyc.connect("localhost", 18861, config={"allow_public_attrs": True}) except: print 'Server not running' sys.exit(0) # get remote objects solution = conn.root.solution()(None) dac_controller = conn.root.dac_controller() # Do shuttle class Region: def __init__(self, center, width, sym_scale, asym_scale): self.region_name = 'Q' self.sub_electrode = True self.width = width self.center = center self.sym_scale = sym_scale self.asym_scale = asym_scale self.solution = solution start_region = Region(9, 0, 1, 0)
def __init__(self): self.conn = rpyc.connect(HOST, PORT)
if __name__ == "__main__": PORT = int(sys.argv[1]) DATA_DIR = sys.argv[2] if not os.path.isdir(DATA_DIR): os.mkdir(DATA_DIR) logging.debug("starting minion") rpyc_logger = logging.getLogger('rpyc') rpyc_logger.setLevel(logging.WARN) getIp = http.client.HTTPConnection("ifconfig.me") getIp.request("GET", "/ip") ip = getIp.getresponse().read() con = rpyc.connect(MASTER_IP, port=MASTER_PORT) result = con.root.get_updates(ip, PORT) if result: logging.debug('Getting updates...') for file, minions_with_file in result: file_path = os.path.join(DATA_DIR, file) dir_arr = file.split('/')[:-1] create_dir = DATA_DIR for dir in dir_arr: create_dir = os.path.join(create_dir, dir) if not os.path.isdir(create_dir): os.mkdir(create_dir) if not os.path.exists(file_path): logging.debug('Getting file ' + file) for minion in minions_with_file:
import rpyc if __name__ == '__main__': # 调用服务器端的方法,格式为:conn.root.xxx。xxx代表服务器端的方法名 # sum是服务端的那个以"exposed_"开头的方法 # RPYC没有认证机制,任何客户端都可以直接访问服务器端的暴露的方法 conn = rpyc.connect('localhost', 9999) result = conn.root.sum(1234, 5678) conn.close() print('>>>', result)
import sys import rpyc from master import MASTER_PORT ############################################################################### # Connection ############################################################################### try: Connection = rpyc.connect("localhost", port=MASTER_PORT) Master = Connection.root.Master() except ConnectionRefusedError: print('Failed to connect to Master.') sys.exit(1) ############################################################################### # End of Connection ############################################################################### # there are some ADMIN APIs we might want to consider. def create_minion_node(): pass def attach_minion_node(): pass def switch_master_node(): pass
import rpyc import json with open( "D:\Code\HackTest\CrowdCompute_Hackathon\src\demo\\recepient\donors.json" ) as f: active_donors = json.load(f) connObjectList = [] results = [] def connObj(obj): connObjectList.append(obj) for i in active_donors: connObj(rpyc.connect(f"{active_donors[i]}", 18861)) for i in connObjectList: results.append(rpyc.async_(i.root.get_answer)) k1 = results[0](82228) k2 = results[1](10423) while (k1.ready == False and k2.ready == False): pass print(f" \n \n {k1.value}, {k2.value}\n \n ")
def __init__(self, host="localhost", port=8001): self.c = rpyc.connect(host, port)
def __init__(self): # connect to the master con_master = rpyc.connect('localhost', port=18861) master_sever = con_master.root self.master = master_sever
def __init__(self, host, port, timeout=240): c = rpyc.connect(host, port) c._config['sync_request_timeout'] = timeout self.proxy = c.root