Skip to main content

A small module that lets you easily create timers that will run a callback function when a certain amount of time has been waited.

Project description

pysimpletimers

This simple, yet useful module will help you to create simple timers that will execute a callback function at the right moment.

(https://github.com/Ilunawoo/pySimpleTimers)

Hope this will ever be useful to someone, it was fun to make.

The Timer object inherit from the threading.Thread object, but you don't need to think about that at all, everything is being taken care of internally.


A Timer object need 4 arguments when initialized, example below:

my_timer = Timer(delay = 5, callback = my_func, args = (a_string, an_int, ....), loop = False)
  • delay: int or float; represents the waiting time in seconds before executing the callback

  • callback: function; your function

  • args: tuple; a tuple containing the args that will be used in your callback, is necessary even if your callback doesn't use args

  • loop: bool; whether your timer will start over when it's finished or not


There are some useful funcs to use with these Timer objects and vars that can be modified:

----- functions -----

  • timer_obj.start(): DOESN'T start a thread, this function override the original Thread.start() function, it only starts the timer, can be called MORE than one time, if the timer is already started, it will restart it from 0

  • timer_obj.stop(): stops the timer but doesn't set its current time to 0

  • timer_obj.quit(): stops the timer and KILL THE THREAD, after that the timer can't be restarted and is only useful to access its data


----- vars -----

  • timer_obj.current_time: int or float, you should definitely not modify this, var containing the current time of the timer

The vars bellow can be modified even if the timer is already started but it can still cause errors, you should call the .stop() function before changing them (because the timer is a thread, it is possible, yet very unlikely, that you'll modify something at the same moment that it's being called, and then raise an error).

  • sleep_time: int or float, the time that will be wait before checking if the delay has been exceded or not (need to be precise or not, at your convenience) NEED TO BE GREATER THAN 0

  • timer_obj.delay: int or float, set at the timer's creation, duration of the timer (time waited before the execution of the callback)

  • timer_obj.callback: function, set at the timer's creation, function called when the timer is completed

  • self.args: tuple, set at the timer's creation, args of the callback function, need to be a tuple

  • self.loop: bool, set at the timer's creation, True if the timer will repeats when it's completed

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysimpletimers-0.0.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysimpletimers-0.0.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pysimpletimers-0.0.4.tar.gz.

File metadata

  • Download URL: pysimpletimers-0.0.4.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for pysimpletimers-0.0.4.tar.gz
Algorithm Hash digest
SHA256 8a09359225ddf1d27376345ccb71e2747a872facd69407baeff3089f814724ea
MD5 9b4cd8e14a245aadb97e60fba39b1fdd
BLAKE2b-256 09ce41ae33ed680f45cc522320866cffb5c8b2cd8df4463815597106e4cdf631

See more details on using hashes here.

File details

Details for the file pysimpletimers-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pysimpletimers-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for pysimpletimers-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3dcd2ef4698933f1a44db8c110be82f90275d66ca10531e90a57730f6db48fc1
MD5 02e89ac321c557fabda91241e5bbd151
BLAKE2b-256 2f863fae443af1449325176e470b655df89cfc462af90d6f3a35f3b9c8798b1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page