[英]Python threading only launching one extra thread
import socket
import thread
s = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
s.connect(("server", 6661))
def recv():
while 1:
print(s.recv(1024))
def send():
while 1:
msg = raw_input("> ")
s.send(msg)
thread.start_new_thread(recv())
thread.start_new_thread(send())
为什么代码在线程recv()之后无法运行-我看不到它应该挂在哪里
调整如下:
thread.start_new_thread(recv, ())
thread.start_new_thread(send, ())
通过追加()
函数名之后,你可以调用recv
和send
在主线程,而不是在新的线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.