[英]Two different while loops run simultaneously in Tkinter (python)
[英]Run two while loops without tkinter or thread modules
如何使兩個while循環同時運行? 這是我的代碼設計。
while True:
print(recieve_message()) #this waits for the message
send_message(input()) #this also waits for the input
這將不起作用,因為兩個代碼都必須等待才能運行。 因此,我希望它們在單獨的循環中運行,如下所示:
while True:
print(recieve_message())
while True:
send_message(input())
如何使這些代碼同時運行?
recieve_message
和
send_message
使用套接字模塊。
您可以使用多線程:
import threading
def f1():
while True:
print(recieve_message()) #this waits for the message
def f2():
while True:
send_message(input()) #this also waits for the input
threading.Thread(target=f1).start()
threading.Thread(target=f2).start()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.