[英]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.