本文整理匯總了Python中multiprocessing.connection.Connection.send_bytes方法的典型用法代碼示例。如果您正苦於以下問題:Python Connection.send_bytes方法的具體用法?Python Connection.send_bytes怎麽用?Python Connection.send_bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing.connection.Connection
的用法示例。
在下文中一共展示了Connection.send_bytes方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _handle
# 需要導入模塊: from multiprocessing.connection import Connection [as 別名]
# 或者: from multiprocessing.connection.Connection import send_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()
示例2: RawSocketHandler
# 需要導入模塊: from multiprocessing.connection import Connection [as 別名]
# 或者: from multiprocessing.connection.Connection import send_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()
示例3: receive_sync
# 需要導入模塊: from multiprocessing.connection import Connection [as 別名]
# 或者: from multiprocessing.connection.Connection import send_bytes [as 別名]
def receive_sync(cls, data_conn: Connection):
data_conn.send_bytes(rtlsdr.read_sync())
示例4: receive_sync
# 需要導入模塊: from multiprocessing.connection import Connection [as 別名]
# 或者: from multiprocessing.connection.Connection import send_bytes [as 別名]
def receive_sync(cls, data_conn: Connection):
if cls.pyaudio_stream:
data_conn.send_bytes(cls.pyaudio_stream.read(cls.CHUNK_SIZE))
示例5: receive_sync
# 需要導入模塊: from multiprocessing.connection import Connection [as 別名]
# 或者: from multiprocessing.connection.Connection import send_bytes [as 別名]
def receive_sync(cls, data_conn: Connection):
if cls.pyaudio_stream:
data_conn.send_bytes(cls.pyaudio_stream.read(cls.CHUNK_SIZE, exception_on_overflow=False))