当前位置: 首页>>代码示例>>Python>>正文


Python Connection.recv_bytes方法代码示例

本文整理汇总了Python中multiprocessing.connection.Connection.recv_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.recv_bytes方法的具体用法?Python Connection.recv_bytes怎么用?Python Connection.recv_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.connection.Connection的用法示例。


在下文中一共展示了Connection.recv_bytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RawSocketHandler

# 需要导入模块: from multiprocessing.connection import Connection [as 别名]
# 或者: from multiprocessing.connection.Connection import recv_bytes [as 别名]
    class RawSocketHandler(socketserver.BaseRequestHandler):
        def setup(self):
            registry.append(self)

        def handle(self):
            self.conn = Connection(self.request.detach())
            while self.conn._handle:
                try:
                    obj = json.loads(self.conn.recv_bytes().decode('utf-8'))
                except EOFError:
                    break
                if obj['type'] == 'message':
                    bus.post(nt_from_dict(Message, obj['message'], None))
                    self.conn.send_bytes(json.dumps({'ret': True}).encode('utf-8'))
                elif obj['type'] == 'request':
                    m = bus.post_sync(nt_from_dict(Message, obj['message'], None))
                    if m:
                        ret = {"ret": True, "response": m._asdict()}
                    else:
                        ret = {"ret": False, "response": None}
                    self.conn.send_bytes(json.dumps(ret).encode('utf-8'))

        def send(self, msg):
            if isinstance(msg, Message):
                ret = {"type": "message", "message": msg._asdict()}
            else:
                ret = {"type": "response", "response": msg._asdict()}
            self.conn.send_bytes(json.dumps(ret).encode('utf-8'))

        def finish(self):
            registry.remove(self)

        def close(self):
            self.conn.close()
开发者ID:gumblex,项目名称:orizonhub,代码行数:36,代码来源:rawsocket.py

示例2: _handle

# 需要导入模块: from multiprocessing.connection import Connection [as 别名]
# 或者: from multiprocessing.connection.Connection import recv_bytes [as 别名]
 def _handle(self, conn_lru_dict: LRUCacheType[multiprocessing_connection.Connection, bool],
             conn: multiprocessing_connection.Connection, c_send: multiprocessing_connection.Connection):
     try:
         data = conn.recv_bytes()
         if not data:
             raise EOFError
         self.logger.debug("parse conn %s" % conn)
         # self.logger.debug(data)
         try:
             result = self.handle(data)
             if result is not None:
                 conn.send_bytes(result)
         except Exception:
             self.logger.exception("handle error")
         conn_lru_dict[conn] = True
         c_send.send_bytes(b'ok')
     except OSError:
         self.logger.debug("conn %s was closed" % conn)
         conn.close()
     except EOFError:
         self.logger.debug("conn %s was eof" % conn)
         conn.close()
     except BrokenPipeError:
         self.logger.debug("conn %s was broken" % conn)
         conn.close()
开发者ID:wwqgtxx,项目名称:wwqLyParse,代码行数:27,代码来源:connection_server.py

示例3: _process

# 需要导入模块: from multiprocessing.connection import Connection [as 别名]
# 或者: from multiprocessing.connection.Connection import recv_bytes [as 别名]
 def _process(self, conn_lru_dict: LRUCacheType[multiprocessing_connection.Connection, bool],
              handle_pool: ThreadPool,
              c_recv: multiprocessing_connection.Connection,
              c_send: multiprocessing_connection.Connection,
              wait=multiprocessing_connection.wait):
     while True:
         try:
             for conn in wait(list(conn_lru_dict.keys()) + [c_recv]):
                 if conn == c_recv:
                     c_recv.recv_bytes()
                     continue
                 del conn_lru_dict[conn]
                 if not conn.closed:
                     handle_pool.spawn(self._handle, conn_lru_dict, conn, c_send)
                 else:
                     self.logger.debug("conn %s was closed" % conn)
         except OSError as e:
             if getattr(e, "winerror", 0) == 6:
                 continue
             logging.exception("OSError")
         except:
             logging.exception("error")
开发者ID:wwqgtxx,项目名称:wwqLyParse,代码行数:24,代码来源:connection_server.py

示例4: recv

# 需要导入模块: from multiprocessing.connection import Connection [as 别名]
# 或者: from multiprocessing.connection.Connection import recv_bytes [as 别名]
def recv(conn: Connection):
    while True:
        t = time.time()
        result = SDRPlay.unpack_complex(conn.recv_bytes())
        print("UNPACK", time.time()-t)
开发者ID:jopohl,项目名称:urh,代码行数:7,代码来源:TestSDRPlay.py


注:本文中的multiprocessing.connection.Connection.recv_bytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。