python自动化web测试-定时器

from threading import Timer
import threading
import time
import unittest

global timers
def func_timer():
    print("func_timer 当前时间:%s" % time.ctime())

class timer_test(unittest.TestCase):
    def test_app(self):
        #在2秒钟后执行func_timer,只是执行一次
        timers = threading.Timer(2, func_timer)
        timers.start()
        
		#这次函数调用将无效
        timers = threading.Timer(11, func_timer)
        timers.start()
        
		#如果这里延时10秒比定时函数要短时间的话,该函数将不被执行
        time.sleep(10)
        timers.cancel()

if __name__ == '__main__':
    unittest.main()

猜你喜欢

转载自blog.csdn.net/qq_40904479/article/details/105522174