import time
import threading
class test:
def printer():
for i in range(3):
print('Hello')
time.sleep(5)
def reload():
for i in range(3):
print('hey')
def upload():
print('hii')
if __name__ == '__main__':
thread1 = threading.Thread(target=printer())
thread2 = threading.Thread(target=reload())
thread3 = threading.Thread(target=upload())
thread1.start()
thread3.start()
thread2.start()
thread1.join()
thread2.join()
thread3.join()
print("bye")
print("right")
def doc():
for i in range(3):
print('good')
输出:
hello
hello
hello
hey
hey
hey
hii
bye
right
我要在thread1
,thread2
和thread3
结束后打印def doc。...“ bye”和“ right”由主线程打印,但是doc()没有。 t打印。为什么不打印?
答案 0 :(得分:0)
def doc():
仅定义doc
方法。如果要打印其结果,则需要对其进行调用。我建议您将那个块移动到if
语句之前,然后在您的doc()
语句的最后一行添加一个if
调用。因此,If
块的最后几行如下所示:
print(“bye”)
print(“right”)
doc()