File: processpool.py

package info (click to toggle)
apscheduler 3.11.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 872 kB
  • sloc: python: 7,326; makefile: 6
file content (24 lines) | stat: -rw-r--r-- 592 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Demonstrates how to schedule a job to be run in a process pool on 3 second intervals.
"""

import os
from datetime import datetime

from apscheduler.schedulers.blocking import BlockingScheduler


def tick():
    print(f"Tick! The time is: {datetime.now()}")


if __name__ == "__main__":
    scheduler = BlockingScheduler()
    scheduler.add_executor("processpool")
    scheduler.add_job(tick, "interval", seconds=3)
    print("Press Ctrl+{} to exit".format("Break" if os.name == "nt" else "C"))

    try:
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        pass