- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
In Python, Timer is a subclass of Thread class. Calling the start() method, the timer starts. 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. The Timer is stopped using the cancel() method.
How to create a Timer object
Following is how you can create a Timer object in Python −
threading.Timer(interval, function, args = None, kwargs = None)
Starting a Timer
The timer.start() is used for start the timer. Here’s an example −
Example
import threading # All the text displays after 3 seconds def mytimer(): print("Demo Python Program\n") my_timer = threading.Timer(3.0, mytimer) my_timer.start() print("Bye\n")
Output
Bye Demo Python Program
Cancelling a Timer
The timer.cancel() is used for cancelling the timer. Here’s an example −
Example
import threading def mytimer(): print("Demo 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 Articles
- Python Program to Create a Lap Timer
- Timer in C#
- Making a countdown timer with Python and Tkinter
- How to access Python objects within objects in Python?
- Timer Class in Java
- Timer Interrupts in Arduino
- Timer registers in Arduino
- Watchdog timer in Arduino
- How to get timer ticks at a given time in Python?
- Terminate the timer in Java
- File Objects in Python?
- Barrier Objects in Python
- Cancel the Timer Task in Java
- Timer in C++ using system calls
- Creating Instance Objects in Python

Advertisements