コード例 #1
0
ファイル: registry.py プロジェクト: tvanzyl/rpyc
    def register(self, aliases, port):
        self.logger.info("registering on %s:%s", self.ip, self.port)
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(self.timeout)
        data = brine.dump(("RPYC", "REGISTER", (aliases, port)))

        try:
            try:
                sock.connect((self.ip, self.port))
                sock.send(data)
            except (socket.error, socket.timeout):
                self.logger.warn("could not connect to registry")
                return False
            try:
                data = sock.recv(MAX_DGRAM_SIZE)
            except socket.timeout:
                self.logger.warn("registry did not acknowledge")
                return False
            try:
                reply = brine.load(data)
            except Exception:
                self.logger.warn("received corrupted data from registry")
                return False
            if reply == "OK":
                self.logger.info("registry %s:%s acknowledged", self.ip, self.port)

            return True
        finally:
            sock.close()
コード例 #2
0
ファイル: test_brine.py プロジェクト: chris-/rpyc
def test_brine():
    x = ("he", 7, u"llo", 8, (), 900, None, True, Ellipsis, 18.2, 18.2j + 13,
         slice(1, 2, 3), frozenset([5, 6, 7]), NotImplemented, (1,2))
    assert dumpable(x)
    y = dump(x)
    z = load(y)
    assert x == z
コード例 #3
0
ファイル: registry.py プロジェクト: tvanzyl/rpyc
    def register(self, aliases, port):
        self.logger.info("registering on %s:%s", self.ip, self.port)
        sock = socket.socket(self.sock_family, socket.SOCK_DGRAM)
        try:
            if self.bcast:
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
            data = brine.dump(("RPYC", "REGISTER", (aliases, port)))
            sock.sendto(data, (self.ip, self.port))

            tmax = time.time() + self.timeout
            while time.time() < tmax:
                sock.settimeout(tmax - time.time())
                try:
                    data, address = sock.recvfrom(MAX_DGRAM_SIZE)
                    rip, rport = address[:2]
                except socket.timeout:
                    self.logger.warn("no registry acknowledged")
                    return False
                if rport != self.port:
                    continue
                try:
                    reply = brine.load(data)
                except Exception:
                    continue
                if reply == "OK":
                    self.logger.info("registry %s:%s acknowledged", rip, rport)
                    return True
            else:
                self.logger.warn("no registry acknowledged")
                return False
        finally:
            sock.close()
コード例 #4
0
ファイル: protocol.py プロジェクト: sccn/SNAP
 def _send(self, msg, seq, args):
     data = brine.dump((msg, seq, args))
     self._sendlock.acquire()
     try:
         self._channel.send(data)
     finally:
         self._sendlock.release()
コード例 #5
0
ファイル: protocol.py プロジェクト: pombredanne/rpyc
 def _send(self, msg, seq, args):
     data = brine.dump((msg, seq, args))
     # GC might run while sending data
     # if so, a BaseNetref.__del__ might be called
     # BaseNetref.__del__ must call asyncreq,
     # which will cause a deadlock
     # Solution:
     # Add the current request to a queue and let the thread that currently
     # holds the sendlock send it when it's done with its current job.
     # NOTE: Atomic list operations should be thread safe,
     # please call me out if they are not on all implementations!
     self._send_queue.append(data)
     # It is crucial to check the queue each time AFTER releasing the lock:
     while self._send_queue:
         if not self._sendlock.acquire(False):
             # Another thread holds the lock. It will send the data after
             # it's done with its current job. We can safely return.
             return
         try:
             # Can happen if another consumer was scheduled in between
             # `while` and `acquire`:
             if not self._send_queue:
                 # Must `continue` to ensure that `send_queue` is checked
                 # after releasing the lock! (in case another producer is
                 # scheduled before `release`)
                 continue
             data = self._send_queue.pop(0)
             self._channel.send(data)
         finally:
             self._sendlock.release()
コード例 #6
0
ファイル: registry.py プロジェクト: AJMartel/3DPrinter
 def unregister(self, port):
     self.logger.info("unregistering from %s:%s", self.ip, self.port)
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     if self.bcast:
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
     data = brine.dump(("RPYC", "UNREGISTER", (port,)))
     sock.sendto(data, (self.ip, self.port))
     sock.close()
コード例 #7
0
ファイル: test_brine.py プロジェクト: SilongHu/rpyc
 def test_brine_2(self):
     if is_py3k:
         exec('''x = (b"he", 7, "llo", 8, (), 900, None, True, Ellipsis, 18.2, 18.2j + 13,
              slice(1, 2, 3), frozenset([5, 6, 7]), NotImplemented, (1,2))''', globals())
     else:
         exec('''x = ("he", 7, u"llo", 8, (), 900, None, True, Ellipsis, 18.2, 18.2j + 13,
              slice(1, 2, 3), frozenset([5, 6, 7]), NotImplemented, (1,2))''')
     self.assertTrue(brine.dumpable(x))
     y = brine.dump(x)
     z = brine.load(y)
     self.assertEqual(x, z)
コード例 #8
0
ファイル: registry.py プロジェクト: AJMartel/3DPrinter
 def unregister(self, port):
     self.logger.info("unregistering from %s:%s", self.ip, self.port)
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     sock.settimeout(self.timeout)
     data = brine.dump(("RPYC", "UNREGISTER", (port,)))
     try:
         sock.connect((self.ip, self.port))
         sock.send(data)
     except (socket.error, socket.timeout):
         self.logger.warn("could not connect to registry")
     sock.close()
コード例 #9
0
ファイル: protocol.py プロジェクト: roolebo/rpyc
 def _send(self, msg, seq, args):
     data = brine.dump((msg, seq, args))
     # GC might run while sending data
     # if so, a BaseNetref.__del__ might be called
     # BaseNetref.__del__ must call asyncreq,
     # which will cause a deadlock
     is_gc_enabled = gc.isenabled()
     gc.disable()
     self._sendlock.acquire()
     try:
         self._channel.send(data)
     finally:
         self._sendlock.release()
         if is_gc_enabled:
             gc.enable()
コード例 #10
0
ファイル: registry.py プロジェクト: SilongHu/rpyc
    def discover(self, name):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        with closing(sock):
            sock.settimeout(self.timeout)
            data = brine.dump(("RPYC", "QUERY", (name,)))
            sock.connect((self.ip, self.port))
            sock.send(data)

            try:
                data = sock.recv(MAX_DGRAM_SIZE)
            except (socket.error, socket.timeout):
                servers = ()
            else:
                servers = brine.load(data)
        return servers
コード例 #11
0
ファイル: registry.py プロジェクト: SilongHu/rpyc
    def discover(self, name):
        sock = socket.socket(self.sock_family, socket.SOCK_DGRAM)

        with closing(sock):
            if self.bcast:
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
            data = brine.dump(("RPYC", "QUERY", (name,)))
            sock.sendto(data, (self.ip, self.port))
            sock.settimeout(self.timeout)

            try:
                data, _ = sock.recvfrom(MAX_DGRAM_SIZE)
            except (socket.error, socket.timeout):
                servers = ()
            else:
                servers = brine.load(data)
        return servers
コード例 #12
0
ファイル: registry.py プロジェクト: AJMartel/3DPrinter
 def discover(self, name):
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     if self.bcast:
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
     data = brine.dump(("RPYC", "QUERY", (name,)))
     sock.sendto(data, (self.ip, self.port))
     sock.settimeout(self.timeout)
     
     try:
         try:
             data, addrinfo = sock.recvfrom(MAX_DGRAM_SIZE)
         except (socket.error, socket.timeout):
             servers = ()
         else:
             servers = brine.load(data)
     finally:
         sock.close()
     return servers    
コード例 #13
0
ファイル: registry.py プロジェクト: tvanzyl/rpyc
    def _work(self):
        while self.active:
            try:
                data, addrinfo = self._recv()
            except (socket.error, socket.timeout):
                continue
            try:
                magic, cmd, args = brine.load(data)
            except Exception:
                continue
            if magic != "RPYC":
                self.logger.warn("invalid magic: %r", magic)
                continue
            cmdfunc = getattr(self, "cmd_%s" % (cmd.lower(),), None)
            if not cmdfunc:
                self.logger.warn("unknown command: %r", cmd)
                continue

            try:
                reply = cmdfunc(addrinfo[0], *args)
            except Exception:
                self.logger.exception("error executing function")
            else:
                self._send(brine.dump(reply), addrinfo)
コード例 #14
0
ファイル: registry.py プロジェクト: nomaka/rpyc
    def _work(self):
        while self.active:
            try:
                data, addrinfo = self._recv()
            except (socket.error, socket.timeout):
                continue
            try:
                magic, cmd, args = brine.load(data)
            except Exception:
                continue
            if magic != "RPYC":
                self.logger.warn(f"invalid magic: {magic!r}")
                continue
            cmdfunc = getattr(self, f"cmd_{cmd.lower()}", None)
            if not cmdfunc:
                self.logger.warn(f"unknown command: {cmd!r}")
                continue

            try:
                reply = cmdfunc(addrinfo[0], *args)
            except Exception:
                self.logger.exception('error executing function')
            else:
                self._send(brine.dump(reply), addrinfo)
コード例 #15
0
    def _work(self):
        while self.active:
            try:
                data, addrinfo = self._recv()
            except (socket.error, socket.timeout):
                continue
            try:
                magic, cmd, args = brine.load(data)
            except Exception:
                continue
            if magic != "RPYC":
                self.logger.warn("invalid magic: %r", magic)
                continue
            cmdfunc = getattr(self, "cmd_%s" % (cmd.lower(), ), None)
            if not cmdfunc:
                self.logger.warn("unknown command: %r", cmd)
                continue

            try:
                reply = cmdfunc(addrinfo[0], *args)
            except Exception:
                self.logger.traceback()
            else:
                self._send(brine.dump(reply), addrinfo)