| 1 |
Multiple schedulers |
| 2 |
################### |
| 3 |
|
| 4 |
You can run as many jobs from a single scheduler as you wish. |
| 5 |
However, for larger installations it might be desirable to have multiple schedulers. |
| 6 |
This is supported: |
| 7 |
|
| 8 |
.. code-block:: python |
| 9 |
|
| 10 |
import time |
| 11 |
import schedule |
| 12 |
|
| 13 |
def fooJob(): |
| 14 |
print("Foo") |
| 15 |
|
| 16 |
def barJob(): |
| 17 |
print("Bar") |
| 18 |
|
| 19 |
# Create a new scheduler |
| 20 |
scheduler1 = schedule.Scheduler() |
| 21 |
|
| 22 |
# Add jobs to the created scheduler |
| 23 |
scheduler1.every().hour.do(fooJob) |
| 24 |
scheduler1.every().hour.do(barJob) |
| 25 |
|
| 26 |
# Create as many schedulers as you need |
| 27 |
scheduler2 = schedule.Scheduler() |
| 28 |
scheduler2.every().second.do(fooJob) |
| 29 |
scheduler2.every().second.do(barJob) |
| 30 |
|
| 31 |
while True: |
| 32 |
# run_pending needs to be called on every scheduler |
| 33 |
scheduler1.run_pending() |
| 34 |
scheduler2.run_pending() |
| 35 |
time.sleep(1) |