
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Timer objects in Python
Timer objects are used to create some actions which are bounded by the time period. Using timer object create some threads that carries out some actions. In python Timer is a subclass of Thread class. Using start() method timer is started.
Creating a Timer object
threading.Timer(interval, function, args = None, kwargs = None), this is the syntax of creating timer of Timer object.
Here in this example at first we shall get
Bye
After 3 second it will display
Python program
Example
import threading def mytimer(): print("Python Program\n") my_timer = threading.Timer(3.0, mytimer) my_timer.start() print("Bye\n")
Output
Bye Python Program
Cancelling a timer
timer.cancel() is the syntax for cancelling the timer.
Example
import threading def mytimer(): print("Python Program\n") my_timer = threading.Timer(3.0, mytimer) my_timer.start() print("Cancelling timer\n") my_timer.cancel() print("Bye\n")
Output
Cancelling Timer Bye
- Related Questions & Answers
- Timer in C#
- Python Program to Create a Lap Timer
- Timer Class in Java
- Timer Interrupts in Arduino
- Timer registers in Arduino
- Watchdog timer in Arduino
- How to access Python objects within objects in Python?
- Making a countdown timer with Python and Tkinter
- Terminate the timer in Java
- Barrier Objects in Python
- File Objects in Python?
- Description of 8253 timer
- Python Code Objects
- Cancel the Timer Task in Java
- Timer in C++ using system calls
Advertisements