Home  >  Article  >  Backend Development  >  python定时器(Timer)用法简单实例

python定时器(Timer)用法简单实例

WBOY
WBOYOriginal
2016-06-10 15:10:482076browse

本文实例讲述了python定时器(Timer)用法。分享给大家供大家参考。具体如下:

# encoding: UTF-8
import threading
#Timer(定时器)是Thread的派生类,
#用于在指定时间后调用一个方法。
def func():
  print 'hello timer!'
timer = threading.Timer(5, func)
timer.start()

该程序可实现延迟5秒后调用func方法的功能。

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn