Skip to main content

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

Metadata

Release files for pysimpletimers 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysimpletimers 0.0.4
File Size Uploaded
pysimpletimers-0.0.4.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysimpletimers 0.0.4
File Interpreter ABI Platform
pysimpletimers-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / pysimpletimers-0.0.4.tar.gz

Download URL pysimpletimers-0.0.4.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8a09359225ddf1d27376345ccb71e2747a872facd69407baeff3089f814724ea
BLAKE2b-256 checksum
How to use checksums
09ce41ae33ed680f45cc522320866cffb5c8b2cd8df4463815597106e4cdf631
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / pysimpletimers-0.0.4-py3-none-any.whl

Download URL pysimpletimers-0.0.4-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dcd2ef4698933f1a44db8c110be82f90275d66ca10531e90a57730f6db48fc1
BLAKE2b-256 checksum
How to use checksums
2f863fae443af1449325176e470b655df89cfc462af90d6f3a35f3b9c8798b1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page