这是我的问题。我在lua上有一个服务器,它通过socket发送数据。数据不断地移动——它是一个交换事务流。我的python脚本作为客户端应该接收数据。
def listen():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
sock.connect(("localhost", 1111))
with BytesIO() as response_bytes:
while True:
try:
fragment = sock.recv(8196)
print("ФÑагменÑ: {}".format(fragment))
except Exception:
pass
if __name__ == "__main__":
t2 = threading.Thread(listen())
t2.start()
while True:
print ("test")
主线程等待sock.recv(8196)行。我希望来自套接字的数据被并行接受,并且主流继续工作。当前代码阻止main的性能,直到执行listen。我不熟悉python中的多个任务。什么决定可以?