Skip to main content

Event scheduler 2

Project description

import sched2
sc = sched2.scheduler()

@sc.every(5)
def magic():
    ```python
    print("✨ Magic sparkles every five seconds! ✨")
    ```

sc.run()

The sched2 module extends the general purpose event scheduler sched from Python's standard library. sched2.scheduler is a subclass of sched.scheduler that adds new features such as the every and cron decorators. It's a practical tool for automating tasks that need to run repeatedly after certain time delays or at specific times.

Install

sched2 is available on PyPI.

pip install sched2

How to use

from urllib.request import urlopen
import sched2

# create the scheduler
sc = sched2.scheduler()

# we'll use this to remember the last IP address between runs
last_ip = None


@sc.every(10)  # seconds
def check_ip_address():
    global last_ip  # in case we need to update this

    # get the current IP address
    current_ip = urlopen("https://icanhazip.com/").read().decode("utf-8").strip()

    # if the IP address has changed
    if last_ip != current_ip:
        last_ip = current_ip

        # emit an event to notify the change
        sc.emit("ip_changed", kwargs={"new_ip": current_ip})

@sc.on("ip_changed")  # 'ip_changed' is the event name
def notify_ip_change(new_ip):  # 'new_ip' is the keyword argument passed to the event
    print(f'Your IP address has changed to {new_ip}')

@sc.cron("0 9 * * 1-5")  # every weekday at 9:00
def daily_greeting():
    print(f'Good morning, your current IP address is {last_ip}')

sc.run()

Source Code and Issues

The source code for sched2 is available on GitHub at github.com/medecau/sched2.

You can help improve sched2 by reporting any issues or suggestions on the issue tracker at github.com/medecau/sched2/issues.

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

sched2-0.8.3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

sched2-0.8.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file sched2-0.8.3.tar.gz.

File metadata

  • Download URL: sched2-0.8.3.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for sched2-0.8.3.tar.gz
Algorithm Hash digest
SHA256 1c45c115264adf63001104cdb17e90dea5ca602b5edde097559516a462f0519a
MD5 29c945e3e1ec24d8b1e848ca79305464
BLAKE2b-256 4a9a054b346c4b2c746935626f696a037a9af21484706f0532f2cc378567a2cd

See more details on using hashes here.

File details

Details for the file sched2-0.8.3-py3-none-any.whl.

File metadata

  • Download URL: sched2-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for sched2-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ad4667adc3be5cf0aeab5a2aef6c06dd67aaff855e79bb10f768d05b25ad3e1c
MD5 4485fd14f45815744b6037b6241da49f
BLAKE2b-256 1bda2e1b3d8d4cca83375fe1dd2a95e3d49afb7744445d00e478d823844a879b

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