import threading from time import sleep run = True def test(): while run: print("1") sleep(1) thread = threading.Thread(target=test()) thread.start() while True: print("2") sleep(1)
会一直输出1,但是我想1,2都输出,需要怎么解决?谢谢
import threading from time import sleep run = True def test(): while run: print("1") sleep(1) thread = threading.Thread(target=test()) thread.start() while True: print("2") sleep(1)
会一直输出1,但是我想1,2都输出,需要怎么解决?谢谢
改成 thread = threading.Thread(target=test)