Python线程计数器
我正试着做线程计数器,但我卡住了。我有下面的代码:Python线程计数器,python,multithreading,counter,Python,Multithreading,Counter,我正试着做线程计数器,但我卡住了。我有下面的代码: import threading def Hello(): global t print("Hello!") t = threading.Timer(1, Hello) t.start() Hello() 我怎样才能让循环在5个“你好”之后停止呢?不确定你想完成什么,但这段代码可以工作 import threading count = 0 def hello(): global
import threading
def Hello():
global t
print("Hello!")
t = threading.Timer(1, Hello)
t.start()
Hello()
我怎样才能让循环在5个“你好”之后停止呢?不确定你想完成什么,但这段代码可以工作
import threading
count = 0
def hello():
global count
print("Hello!")
count += 1
if count < 5:
t = threading.Timer(1, function=hello,)
t.start()
hello()
导入线程
计数=0
def hello():
全局计数
打印(“你好!”)
计数+=1
如果计数小于5:
t=threading.Timer(1,函数=hello,)
t、 开始()
你好()
什么是“我卡住了”?作为这里的新用户,请从开始阅读。此外,特别是对于Python,正确的格式设置非常重要!你可以修改你的问题的格式,也许包括一个。谢谢!!!那正是我想要的!