Jupyter notebook 线程。线程不在函数上执行循环
我一直在尝试编写一个自动点击器,但我首先需要学习如何使用线程库,但我不知道为什么代码在循环中第一次运行时就停止了Jupyter notebook 线程。线程不在函数上执行循环,jupyter-notebook,python-3.6,Jupyter Notebook,Python 3.6,我一直在尝试编写一个自动点击器,但我首先需要学习如何使用线程库,但我不知道为什么代码在循环中第一次运行时就停止了 import time from threading import Thread def countdown(n): while n > 0: print('T-minus', n) n -= 1 time.sleep(5) t = Thread(target = countdown, args =(10,
import time
from threading import Thread
def countdown(n):
while n > 0:
print('T-minus', n)
n -= 1
time.sleep(5)
t = Thread(target = countdown, args =(10, ))
t.start()
输出仅为:
>>> T-minus 10
有人能帮我吗?我刚刚明白发生了什么事!如果您试图在Jupyter单元上运行线程,它将不会显示输出,我对代码做了一些修改以测试它
import time
from threading import Thread
TIMES = 0
def countdown(n):
global TIMES
while n > 0:
TIMES += 1
time.sleep(5)
t = Thread(target = countdown, args =(10, ))
t.start()
在下一个单元格中,我一直在打印时间值,它在变化!但是就在幕后
for i in range(10):
time.sleep(3)
print(TIMES)