Ejemplo n.º 1
0
 def initSlaveNodes(self):
     self.logger.info('Connecting with remote servers...')
     for thread in self.threadList:
         thread.stop()
     for conn in self.connList:
         conn.close()
     sleep(10)
     self.connList = []
     self.threadList = []
     self.crawlerList = []
     random.shuffle(self.accounts)
     for serverID, server in enumerate(self.serverPool):
         conn = rpyc.connect(server[0],
                             server[1],
                             config={"allow_pickle": True})
         bgThread = rpyc.BgServingThread(conn)
         accountList = self.accounts[serverID * len(self.accounts) /
                                     len(self.serverPool):(serverID + 1) *
                                     len(self.accounts) /
                                     len(self.serverPool)]
         crawler = conn.root.Crawler(serverID, self.threadCount,
                                     self.dbConfig, accountList,
                                     self.fetchNewJob)
         self.connList.append(conn)
         self.threadList.append(bgThread)
         self.crawlerList.append(crawler)
Ejemplo n.º 2
0
def cmd_transfer(addr, port, full_dir_file_name, cmd_name, timeout_s):
    print("connect server")
    while (1):
        try:
            f = rpyc.connect(addr, port)
            f.root.setCallback(check_and_read)

            bgsrv = rpyc.BgServingThread(f)

            availfiles.append(full_dir_file_name)
            f.root.newfiles_add(full_dir_file_name)

            f.root.save_file(addr, full_dir_file_name)
            f.root.pass_cmd(cmd_name, timeout_s)

            f.root.files_remove(full_dir_file_name)

            bgsrv.stop()
            f.close()
            break
        except Exception, e:
            #			print e
            print "."
            import time
            time.sleep(1)
Ejemplo n.º 3
0
 def login(self,retry = True):
     '''
     Log in to the controller. First try to reach the controller via the standard service registry, 
     if that fails try to access it via the supplied hostname/port arguments. If that fails, sleep a
     little and try again. 
     '''
     while True:
         try:
             self.conn = rpyc.connect_by_service(const.ctrlServiceName,config = {"allow_public_attrs" : True})
             break
         except:
             try:  
                 self.conn = rpyc.connect(self.ctrlrHost,self.ctrlrPort,config = {"allow_public_attrs" : True})
                 break
             except:
                 if retry == False:
                     return False
                 time.sleep(5)
                 continue
     self.bgsrv = rpyc.BgServingThread(self.conn,self.handleBgServingThreadException)       
     resp = self.conn.root.login(self.hostAddress,self.callback,self.riapsApps)
     if type(resp) == tuple and resp[0] == 'dbase':   # Expected response: (redis) database host:port pair
         if self.depm != None:
             self.depm.doCommand(('setDisco',) + resp[1:])
         return True
     else:
         pass    # Ignore any other response
         return False
Ejemplo n.º 4
0
 def __init__(self):
     threading.Thread.__init__(self)
     conn = rpyc.connect("localhost", 12345)
     self.bgsrv = rpyc.BgServingThread(conn, self.backgroundStoppedCb)
     self.bgsrv.SLEEP_INTERVAL = 0.025  #to make the GUI more reactive
     self.bgsrvRunning = True
     self.c = conn.root
Ejemplo n.º 5
0
    def _connect(self, server):
        conn = server.connect(service=rpyc.VoidService)
        bgsrv = rpyc.BgServingThread(conn)

        conn.ping(timeout=15)

        return self.ConnType(conn, bgsrv)
Ejemplo n.º 6
0
    def connect(self):
        fn_server_public = os.path.expanduser(constants.FN_SERVER_CERT_PUBLIC)
        xt_server_cert = self.config.get_vault_key("xt_server_cert")

        use_public_half = False  # cannot get the public half approach to work

        try:
            # write CERT file JIT
            if use_public_half:
                _, public_half = xt_server_cert.split("END PRIVATE KEY-----\n")
                file_utils.write_text_file(fn_server_public, public_half)
            else:
                file_utils.write_text_file(fn_server_public, xt_server_cert)

            self.conn = rpyc.ssl_connect(self.ip,
                                         port=self.port,
                                         keyfile=None,
                                         certfile=fn_server_public)

            if self.conn:
                # magic step: allows our callback to work correctly!
                # this must always be executed (even if self.conn is already true)
                self.bgsrv = rpyc.BgServingThread(self.conn)
                console.diag("  now running BgServingThread")
        finally:
            # delete the CERT file
            #os.remove(fn_server_public)
            pass

        connected = not (not self.conn)
        return connected
Ejemplo n.º 7
0
 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]
Ejemplo n.º 8
0
    def on_connect(self, conn: rpyc.Connection) -> None:
        """Initializes thread for the incoming connection.

        Args:
            conn: An incoming connection.
        """

        self._bg_threads[conn] = rpyc.BgServingThread(conn)
Ejemplo n.º 9
0
 def test_rpyc(self):
     p1, p2 = PipeStream.create_pair()
     client = rpyc.connect_stream(p1)
     server = rpyc.connect_stream(p2)
     server_thread = rpyc.spawn(server.serve_all)
     assert client.root.get_service_name() == "VOID"
     t = rpyc.BgServingThread(client)
     assert server.root.get_service_name() == "VOID"
     t.stop()
     client.close()
     server.close()
     server_thread.join()
async def startup():
    global conn, bgsrv, scheduler

    try:
        conn = rpyc.connect("localhost", 12345)
        # create a bg thread to process incoming events
        bgsrv = rpyc.BgServingThread(conn)
        scheduler = conn.root
    except ConnectionRefusedError as e:
        logger.error("请先执行 rpc_server.py,否则无法使用web")
        raise
    await database.connect()
Ejemplo n.º 11
0
 def connect_on_client(self, launcher_args):
     """ connect on a client that would be running a bind payload """
     launcher=network.conf.launchers["connect"](connect_on_bind_payload=True)
     try:
         launcher.parse_args(shlex.split(launcher_args))
     except LauncherError as e:
         launcher.arg_parser.print_usage()
         return
     stream=launcher.iterate().next()
     self.handler.display_info("Connecting ...")
     conn=rpyc.utils.factory.connect_stream(stream, PupyService.PupyBindService, {})
     bgsrv=rpyc.BgServingThread(conn)
     bgsrv.SLEEP_INTERVAL=0.001 # consume ressources but faster response ...
Ejemplo n.º 12
0
    def __init__(self, name, callback=None, address="localhost", port=18812):
        self._name = name
        conn = None
        while conn is None:
            try:
                service = classpartial(MessagingClientService, name, callback)
                conn = rpyc.connect(address, port, service=service)
                self._conn = conn
            except Exception as e:
                print(e, file=sys.stderr)
                print("Retry in 5sec...")
                time.sleep(5)

        rpyc.BgServingThread(self._conn)
Ejemplo n.º 13
0
    def __init__(self, mach, porta):
        import rpyc, data, erros, sys, time

        errors = erros.logger("cliente_erros.log")
        errors.calee = "cliente.py"
        try:
            self.con = rpyc.connect(mach, port=porta)
            self.bgsrv = rpyc.BgServingThread(self.con)
        except:
            errors.reg("Server not available, check connection", 3)
            sys.exit()
        self.fetcher = data.Fetcher(1)
        self.fetcher.work_start()
        self.datalogger = True
Ejemplo n.º 14
0
    def __init__(self, host, port, normalize_imgs=True, force_cpu=False):
        """ A simple FID-client that talks to the FID server and posts fid calculation requests

        :param host: the FID-server hostname or ip
        :param port: the FID-server port
        :param normalize_imgs: whether to normalize the images
        :param force_cpu: force calculations on CPU (not recommended)
        :returns: FIDClient Object
        :rtype: object

        """
        self.cfg = {'allow_pickle': True, "sync_request_timeout": 180}
        self.conn = rpyc.connect(host, port, config=self.cfg)
        self.bgsrv = rpyc.BgServingThread(self.conn)
        self.fid = self.conn.root.FID(normalize=normalize_imgs,
                                      force_cpu=force_cpu)
Ejemplo n.º 15
0
 def login(self, retry=True):
     self.logger.info("login()")
     self.conn = None
     while True:
         try:
             addrs = rpyc.utils.factory.discover(GLAClient.SERVICENAME)
             for host, port in addrs:
                 try:
                     self.conn = rpyc.connect(
                         host, port, config={"allow_public_attrs": True})
                 except socket.error as e:
                     self.logger.error("%s.%s: %s" %
                                       (str(host), str(port), str(e)))
                     pass
                 if self.conn: break
         except DiscoveryError:
             self.logger.error("discovery of %s failed" %
                               (GLAClient.SERVICENAME))
             pass
         if self.conn: break
         if self.host and self.port:
             try:
                 self.conn = rpyc.connect(
                     self.host,
                     self.port,
                     config={"allow_public_attrs": True})
             except socket.error as e:
                 self.logger.error("%s.%s: %s" %
                                   (str(host), str(port), str(e)))
                 pass
         if self.conn: break
         if retry == False:
             return False
         else:
             time.sleep(5)
             continue
     self.bgsrv = rpyc.BgServingThread(self.conn,
                                       self.handleBgServingThreadException)
     resp = None
     try:
         resp = self.conn.root.login(self.name, self.callback)
     except:
         traceback.print_exc()
         pass
     return type(resp) == tuple and resp[0] == 'ok'
Ejemplo n.º 16
0
 def __init__(self, self_play=False, player=1):
     assert player == 1 or player == 2
     self.action_space = spaces.Discrete(7)
     self.observation_space = spaces.Box(low=-np.inf,
                                         high=np.inf,
                                         shape=(69, 26, 26),
                                         dtype=float)
     self.player = player
     self.self_play = self_play
     self.sct = mss.mss()
     self.state = {
         'stats': {
             'kills': 0,
             'deaths': 0,
             'assists': 0,
             'minion_kills': 0,
             'health': 100,
             'opponent_health': 100
         },
         'positions': defaultdict(lambda: None)
     }
     self.champion = 'Ashe'
     self.opponent = 'Veigar'
     self.opponent_template = cv2.imread(self.opponent + '.jpg', 0)
     self.start_time = time.time()
     self.away_time = time.time()
     performDetect(initOnly=True,
                   configPath="./cfg/yolov3-tiny_obj.cfg",
                   weightPath="yolov3-tiny_obj_last.weights",
                   metaPath="./cfg/obj.data")
     if self_play:
         self.service = Service()
         if player == 1:
             self.conn = rpyc.OneShotServer(self.service, port=18861)
             self.server = Thread(target=self.conn.start)
             self.server.start()
         else:
             self.champion = 'Veigar'
             self.opponent = 'Ashe'
             self.conn = rpyc.connect("localhost",
                                      18861,
                                      service=self.service)
             self.bgsrv = rpyc.BgServingThread(self.conn)
Ejemplo n.º 17
0
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(
            HComMayaUtils.readIni()["SERVER"].replace(" ", ""),
            int(str(HComMayaUtils.readIni()["PORT"]).replace(" ", "")),
            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():
            ask = QtGui.QMessageBox()
            ask.setText("User ID already registered on the server")
            ask.setIcon(QtGui.QMessageBox.Critical)
            ask.exec_()
            server_conn.close()
            return False

        MayaGlobals.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
Ejemplo n.º 18
0
    def _connect(self, port):

        self._logger.debug(f'Trying to connect on port {port}')

        for i in range(self.patience):
            try:
                self._logger.debug(f'Attempt no: {i}')

                conn = rpyc.connect(host="localhost",
                                    port=port,
                                    service=rpyc.VoidService)
                bgsrv = rpyc.BgServingThread(conn)

                conn.ping()

                return self.ConnType(conn, bgsrv)

            except ConnectionRefusedError:
                time.sleep(2)

        raise ConnectionRefusedError
Ejemplo n.º 19
0
    def connect_to_controller(self, box_name=None, ip_addr=None, port=None):
        '''
        establish communication with the XT controller process on the specified box.
        return True if connection established, False otherwise.
        '''
        connected = False
        console.diag("init_controler: box_name={}".format(box_name))

        if self.conn == box_name:
            connected = True
        else:
            if ip_addr:
                box_addr = ip_addr
            else:
                info = box_information.get_box_addr(self.config, box_name,
                                                    self.store)
                box_addr = info["box_addr"]
                controller_port = info["controller_port"]
                self.token = info["box_secret"]

                ip_addr = self.core.get_ip_addr_from_box_addr(box_addr)
                port = controller_port if controller_port else constants.CONTROLLER_PORT

            # the controller should now be running - try to connect
            try:
                console.diag("  connecting to controller")
                self.connect(box_name, ip_addr, port=port)
                console.diag("  connection successful!")

                # magic step: allows our callback to work correctly!
                # this must always be executed (even if self.conn is already true)
                bgsrv = rpyc.BgServingThread(self.conn)
                console.diag("  now running BgServingThread")
                connected = True
            except BaseException as ex:
                #self.report_controller_init_failure(box_name, box_addr, self.port, ex)
                # most common reasons for failure: not yet running (backend service) or finished running
                pass

        return connected
Ejemplo n.º 20
0
 def connect_to_moose_server(self, host, port, pid, filename):
     try:
         DEBUG("Connecting to Moose server on " + host + ":" + str(port))
         connection = rpyc.classic.connect(host, port)
         INFO("Connected to Moose server on " + host + ":" + str(port))
         modelname = self.unique_modelname(filename)
         connection.modules.moose.loadModel(filename, modelname)
         INFO("Loaded " + modelname)
         self.current_model = self.models[modelname] = \
             { "conn"     :   connection
             , "moose"    :   connection.modules.moose
             , "pid"      :   pid
             , "host"     :   host
             , "port"     :   port
             , "model"    :   connection.modules.moose.element(modelname)
             , "service"  :   connection.root
             , "thread"   :   rpyc.BgServingThread(connection)
             }
     except socket.error as serr:
         if serr.errno != errno.ECONNREFUSED:
             raise serr
         DEBUG("Failed to connect to Moose server on " + host + ":" + str(port))
         QTimer.singleShot(1000, lambda : self.connect_to_moose_server(host, port, pid, filename))
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
from sklearn.neural_network import MLPClassifier
from random import randint
import rpyc
import pandas as pd

conn = rpyc.classic.connect(
    '169.254.229.60')  # host name or IP address of the EV3
bgsrv = rpyc.BgServingThread(conn)  #sleep removed

sensors = conn.modules['ev3dev2.sensor.lego']
motor = conn.modules['ev3dev2.motor']

distancia = sensors.UltrasonicSensor()
color = sensors.ColorSensor()

llantaIzq = motor.LargeMotor(motor.OUTPUT_D)
llantaDer = motor.LargeMotor(motor.OUTPUT_A)

llantas = motor.MoveTank(motor.OUTPUT_A, motor.OUTPUT_D)

rampa = motor.Motor(motor.OUTPUT_B)

accion = " "

degrees = 0
maxDegrees = 10


def Caminar(Speed):
    llantas.on(Speed, Speed)
Ejemplo n.º 23
0
 def setup(self):
     self.conn = rpyc.connect_thread(remote_service=MyService)
     self.bgserver = rpyc.BgServingThread(self.conn)
Ejemplo n.º 24
0
 def test_rpyc(self):
     assert self.client.root.get_service_name() == "VOID"
     t = rpyc.BgServingThread(self.client)
     assert self.server.root.get_service_name() == "VOID"
     t.stop()
Ejemplo n.º 25
0
import rpyc
import time

c = rpyc.classic.connect("localhost")
t = rpyc.BgServingThread(c)

start = time.time()
for i in range(100):
    c.execute("newObj = %d" % (i))
stop = time.time()
print "added %d simple objects one by one, %f seconds" % (100, stop - start)

t.stop()

Ejemplo n.º 26
0
def _connect_rpc(worker):
    conn = rpyc.connect(worker.kuyruk.config.MANAGER_HOST,
                        worker.kuyruk.config.MANAGER_PORT,
                        service=_worker_service_class(worker),
                        config={"allow_pickle": True})
    rpyc.BgServingThread(conn)._thread.join()
Ejemplo n.º 27
0
def init_conn(host):
    conn = rpyc.classic.connect(host)
    t = rpyc.BgServingThread(conn)
    return conn
Ejemplo n.º 28
0
 def login(self, retry=True):
     '''
     Log in to the controller. First try to reach the controller via the standard service registry,
     if that fails try to access it via the supplied hostname/port arguments. If that fails, sleep a
     little and try again.
     '''
     while True:
         self.conn = None
         try:
             addrs = rpyc.utils.factory.discover(const.ctrlServiceName)
             for host, port in addrs:
                 try:
                     if Config.SECURITY:
                         self.conn = rpyc.ssl_connect(
                             host,
                             port,
                             keyfile=self.keyFile,
                             certfile=self.certFile,
                             cert_reqs=ssl.CERT_REQUIRED,
                             ca_certs=self.certFile,
                             config={"allow_public_attrs": True})
                     else:
                         self.conn = rpyc.connect(
                             host,
                             port,
                             config={"allow_public_attrs": True})
                 except socket.error:
                     pass
                 if self.conn: break
         except DiscoveryError:
             pass
         if self.conn: break
         if self.ctrlrHost and self.ctrlrPort:
             try:
                 if Config.SECURITY:
                     self.conn = rpyc.ssl_connect(
                         self.ctrlrHost,
                         self.ctrlrPort,
                         keyfile=self.keyFile,
                         certfile=self.certFile,
                         cert_reqs=ssl.CERT_REQUIRED,
                         ca_certs=self.certFile,
                         config={"allow_public_attrs": True})
                 else:
                     self.conn = rpyc.connect(
                         self.ctrlrHost,
                         self.ctrlrPort,
                         config={"allow_public_attrs": True})
             except socket.error:
                 pass
         if self.conn: break
         if retry == False:
             return False
         else:
             time.sleep(5)
             continue
     self.bgsrv = rpyc.BgServingThread(self.conn,
                                       self.handleBgServingThreadException)
     resp = None
     try:
         resp = self.conn.root.login(self.hostAddress, self.callback,
                                     self.riapsApps)
     except:
         pass
     if type(resp) == tuple and resp[
             0] == 'dbase':  # Expected response: (redis) database host:port pair
         if self.depm != None:
             self.depm.doCommand(('setDisco', ) + resp[1:])
         return True
     else:
         pass  # Ignore any other response
         return False
Ejemplo n.º 29
0
import rpyc
import time

count = 0


def callbackFunc(x):
    global count
    count += 1
    print x, time.time()


if __name__ == "__main__":
    conn = rpyc.connect("localhost", 12000)
    #rpyc.BgServingThread.SERVE_INTERVAL = 0.01
    rpyc.BgServingThread.SLEEP_INTERVAL = 0.0001
    bgsrv = rpyc.BgServingThread(conn)

    test = conn.root.RemoteCallbackTest(callbackFunc)
    print test
    test.start()
    print "doing other things while the callback is being called"
    while count < 100:
        time.sleep(0.1)
    print "done"
Ejemplo n.º 30
0
    def run(self):
        """Run the managing loop. Check rqt stack for simulation request. Select the candidate \
        server for simulation. Start simulation."""

        logging.info("Start Sim Manager main loop")

        # Continue while not asked for termination or when there are candidates in the list
        # and a server to process them
        while (not self.mng_stop) or (self.rqt and self.server_dispo):

            if self.rqt:

                # Select a candidate server
                server_hash = self.__select_candidate()

                if server_hash != 0:

                    # We found a server
                    self.server_dispo = True
                    logging.info(
                        "Starting sim service on server: " +
                        str(self.cloud_state[server_hash]["address"]) + ":" +
                        str(self.cloud_state[server_hash]["port"]))

                    # Connect to candidate server
                    try:
                        conn = rpyc.connect(
                            self.cloud_state[server_hash]["address"],
                            self.cloud_state[server_hash]["port"])

                    except Exception as e:
                        logging.error("Exception when connecting:" + str(e))
                        pass

                    # Update the cloud_state list
                    self.mutex_cloud_state.acquire()
                    self.cloud_state[server_hash]["n_threads"] += 1
                    self.mutex_cloud_state.release()

                    # Create serving thread to handle answer
                    try:
                        bgt = rpyc.BgServingThread(conn)
                    except Exception as e:
                        logging.error("Exception in serving thread:" + str(e))
                        pass

                    self.mutex_conn_list.acquire()
                    self.conn_list.append({
                        "server": server_hash,
                        "conn": conn,
                        "thread": bgt
                    })
                    self.mutex_conn_list.release()

                    # Create asynchronous handle
                    async_simulation = rpyc. async (
                        conn.root.exposed_simulation)

                    try:
                        # Call asynchronous service
                        res = async_simulation(self.rqt[-1])

                        # Assign asynchronous callback
                        res.add_callback(self.response_sim)

                    except Exception as e:
                        logging.error("Exception from server:" + str(e))
                        pass

                    # Clear request from list: TODO: check if async_simulation don't need it anymore!
                    self.mutex_rqt.acquire()
                    self.rqt.pop()
                    self.mutex_rqt.release()

                else:
                    self.server_dispo = False
                    time.sleep(self.mng_prun_t)

            else:
                time.sleep(self.mng_prun_t)

        logging.info("Simulation Manager has terminated properly!")
        self.terminated = True