Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.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_Timer_Pyqt4_Python 3.3 - Fatal编程技术网

Python 在程序执行其他命令时,如何创建要运行的测验计时器?

Python 在程序执行其他命令时,如何创建要运行的测验计时器?,python,timer,pyqt4,python-3.3,Python,Timer,Pyqt4,Python 3.3,如上问题所述,我想创建/实现一个用于数学测试程序的计时器,以便用户可以在系统执行各种命令时查看计时器。 我试过很多定时器,比如: import time s=0 m=0 while s<=60: os.system('cls') print (m, 'Minutes', s, 'Seconds') time.sleep(1) s+=1 if s==60: m+=1 s=0 但是,顶部计时器要求系统睡眠。因此,如

如上问题所述,我想创建/实现一个用于数学测试程序的计时器,以便用户可以在系统执行各种命令时查看计时器。 我试过很多定时器,比如:

import time


s=0
m=0

while s<=60:
    os.system('cls')
    print (m, 'Minutes', s, 'Seconds')
    time.sleep(1)
    s+=1
    if s==60:
        m+=1
        s=0

但是,顶部计时器要求系统睡眠。因此,如果我在数学测试程序中实现这一点,用户将无法输入任何数据或执行任何操作,因为系统会持续休眠。同样,在使用第二种方法时,我必须再次创建某种while循环,以便在达到时间限制时传递信号/警报,但这将再次使系统冻结。我有没有办法实现某种计时器,使程序能够同时运行?

您需要执行同步进程来执行您想要的操作。在您的例子中,您可以简单地使用队列作为通信通道,并在每次循环执行之前执行非阻塞读取。Python提供了stdlib和。这并不是在所有情况下都有效,但就我所知,您似乎并不需要太多。您是否有机会进一步解释我如何在代码中实现这一点?这里有几个示例,只需进行一些搜索-例如:may of interest。
import sys
import os
import time
import datetime

current_time = datetime.datetime.now().time()
current_time = str(current_time)
current_time = current_time[:-7]
print(current_time)

if current_time = #set-the-time:
    #Do something