Cosmovex Tools

Scheduled Python script stopped running? Ping from the script, get alerted when it stops.

Python scripts with Cronwatch

This check expects a Python job every hour. The Python snippet uses only the standard library, so there is nothing to install on the machine that runs the script.

  1. Create the check with an hourly schedule and 15 minutes of grace.
  2. Copy the Python snippet and call urlopen after your work finishes.
  3. Wrap the work in try/except and request the /fail URL in the except block to alert on errors immediately.
  4. Run the script once and confirm the check turns UP.
monitor python script python cron job monitoringscheduled python script alertpython script stopped runningpython heartbeat
Open Cronwatch Free · Pro $5/mo · no account

What to know

Scripts started by cron, Task Scheduler, a container or a hosting platform tend to fail outside anyone's view: an expired API token, a changed schema or a missing package raises an exception into a log that nobody reads. A ping at the end of the script is the simplest proof that it ran to completion.

Use urllib.request from the standard library with a timeout so the script never hangs on the ping. If requests is already a dependency, requests.get(url, timeout=10) works the same. Put the ping after the work, not before, so it means "finished" rather than "started".

For long-running jobs, ping the /start URL at the beginning as well. Cronwatch then shows how long each run took, which is how you spot a job that is slowly getting slower before it starts overlapping with the next run.

Updated · Cosmovex

Questions

Do I need to install a package?

No. The snippet uses urllib from the Python standard library.

How do I report an exception?

In your except block, request the check URL with /fail appended. The check goes down immediately and you get an alert.

Will a slow network block my script?

Not for long. The snippet sets a 10-second timeout; wrap it in try/except if you never want monitoring to raise.

Does it work on serverless schedules?

Yes. Any scheduler that can make an HTTPS request at the end of a run can ping a check.

The free plan covers everything on this page. Cronwatch Pro ($5/mo, billed monthly) is described on the Cronwatch page.