Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python线程计数器_Python_Multithreading_Counter - Fatal编程技术网

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,正确的格式设置非常重要!你可以修改你的问题的格式,也许包括一个。谢谢!!!那正是我想要的!