Easily schedule multiple events and recurring tasks (simultaneously).
Project description
simple_scheduler
- Uses multiprocessing to schedule light jobs.
- This package uses a 24-hour clock, only.
- Simultaneously schedule any number of jobs.
- Recurring jobs to be precisely sheduled.
- Event jobs to be executed within the minute.
Install
From PyPi :
pip install simple-scheduler
How to use?
Quick-start
See examples folder.
Long
There are two different schedulers:
>>> from simple_scheduler.event import event_scheduler
>>> from simple_scheduler.recurring import recurring_scheduler
Purpose of each scheduler:
>>> print(event_scheduler.__doc__)
Event occurs at an exact time.
e.g. scirpt_1 is called at 14:00 and 20:00
Each event is tried 3-times (but executed only once).
>>> print(recurring_scheduler.__doc__)
Recurring tasks are those that occur after every "x"-seconds.
(e.g. script_1 is called every 600 seconds)
Using only event_scheduler
>>> print(event_scheduler.add_job.__doc__)
Assigns an event to a process.
Parameters
----------
target : a callable function
tz : str
time zone (call the method .timezones() for more info)
when : list, a collection of "day|HH:MM"
at what precise time(s) should the function be called
eg. ["mon|22:04","sat|03:45", ...] please "only" use 24-hour
clock with "|" as day separator
and ":" as time separator
args : tuple(object,), optional
un-named argumets for the "target" callable
the default is ()
kwargs : dict{key:object}, optional
named argumets for the "target" callable
the default is {}
Raises
------
Exception
- If time (in "when"-list) is not a collection of "int:int"
eg. ["tue|12:30am","thu|2:30 pm", ...] please "only" use 24-hour
clock, with "|" as day
separator and ":" as time
separator
Returns
-------
None.
correct argument precedence in a function
>>> def target(a, b=1, *args, **kwargs):
print(a, b, args, kwargs)
Add above target function twice. Each function would be called on timestamps (day|HH:MM) mentioned in list WHEN.
>>> WHEN = ["wed|16:55", "*|16:56"] # "*" --> all days
>>> TZ = "Asia/Kolkata"
>>> event_scheduler.add_job(target= target,
args = (0,), # ... use "," for single arguments
kwargs = {"b":2},
when = WHEN,
tz = TZ)
>>> event_scheduler.add_job(target= target,
args = (0, 2, "arg1", "arg2"),
kwargs = {"key1":"value1",
"key2":"value2"},
when = WHEN,
tz = TZ)
>>> event_scheduler.run()
Wed Mar 17 16:55:32 2021 :: target [event @wed|16:55|Asia/Kolkata]
0 2 () {}
Wed Mar 17 16:55:32 2021 :: target [event @wed|16:55|Asia/Kolkata]
0 2 ('arg1', 'arg2') {'key1': 'value1', 'key2': 'value2'}
Wed Mar 17 16:56:27 2021 :: target [event @wed|16:56|Asia/Kolkata]
0 2 () {}
Wed Mar 17 16:56:27 2021 :: target [event @wed|16:56|Asia/Kolkata]
0 2 ('arg1', 'arg2') {'key1': 'value1', 'key2': 'value2'}
Using only recurrent_scheduler
>>> print(recurring_scheduler.add_job.__doc__)
Assigns an periodic task to a process.
Parameters
----------
target : a callable function
period_in_seconds : int
the time period in seconds to execute this function
args : tuple(object,), optional
un-named argumets for the "target" callable
the default is ()
kwargs : dict{key:object}, optional
named argumets for the "target" callable
the default is {}
Returns
-------
None.
>>> from time import sleep
>>> def wait(t):
sleep(t)
print(f"I waited {t} seconds")
>>> recurring_scheduler.add_job(target=wait,
kwargs={"t":10},
period_in_seconds=5)
>>> recurring_scheduler.run()
Wed Mar 17 17:14:30 2021 :: wait [recurring | 5-second(s)]
Wed Mar 17 17:14:35 2021 :: wait [recurring | 5-second(s)]
I waited 10 seconds
Wed Mar 17 17:14:40 2021 :: wait [recurring | 5-second(s)]
I waited 10 seconds
Wed Mar 17 17:14:45 2021 :: wait [recurring | 5-second(s)]
Note
The execution time of above "wait"-function is 10 seconds. But, is being called every 5-seconds.
Toggle verbose
>>> event_scheduler.verbose = False
>>> recurring_scheduler.verbose = True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simple_scheduler-1.0.6.tar.gz
(5.7 kB
view hashes)
Built Distributions
simple_scheduler-1.0.6-py3.6.egg
(17.1 kB
view hashes)
Close
Hashes for simple_scheduler-1.0.6-py3.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | dde32e1def6b8c732df3ad0b4430e6a8d62ea2d80ef994f01822dd3af51d4815 |
|
MD5 | 0423efc1a816e6d8b64d74671a421c54 |
|
BLAKE2b-256 | 22d4e31e10604688373f4064a00052f96d32f3996bc7e957ac4a904f52fe302f |
Close
Hashes for simple_scheduler-1.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e460bd2bbecd9bdccca55dbe514d0c2a4e0c09583a4f5ce24b403d51dbe757d6 |
|
MD5 | 7294d3815af113ab0c3f9653b5ce65a5 |
|
BLAKE2b-256 | 9b10fd58716c73715bf8285e6f1923171e59c222aba136ce68bfa6798b560f7f |