python3.x: Simple Time scheduling timer (interval execution)

Source: Internet
Author: User

python3.x: Simple Time scheduling timer (interval execution)

Code:

ImportThreadingImport TimedefFun_timer ():Print('Hello Timer')    GlobalTimer#Repeating Construction TimerTimer = Threading. Timer (5.8, Fun_timer) Timer.start ()#Timing SchedulingTimer = Threading. Timer (2, Fun_timer) Timer.start ()#Stop timer after 50 secondsTime.sleep (50) Timer.cancel ()

Description

(1). Threading.timer () There are 2 main parameters: The first parameter is the time, the second parameter is the function name;

(2). The timer must be repeatedly constructed within the timer execution function, since the timer is constructed only 1 times and must be called in a loop;

(3). The Timer interval unit is the second, can be a floating point number, such as 5.5,0.02, such as the first time the Fun_timer is executed after 2 seconds, the back is 5.8 seconds after the execution.

(4). Use Cancel to stop the timer work;

python3.x: Simple Time scheduling timer (interval execution)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.