Best way to schedule Python scripts on macOS?

Začal/a Alex Kumar · pred 3 mesiacmi

A
Alex Kumar pred 4 mesiacmi
I want to run a data sync script every hour. Is launchd better than cron on Mac?
M
Michael Torres pred 3 mesiacmi
launchd is the macOS-native way and more reliable. Create a plist in ~/Library/LaunchAgents/. But honestly, for simple scheduling cron still works fine: `crontab -e` and add `0 * * * * /usr/bin/python3 /path/to/script.py`.
A
Anna Kowalski pred 3 mesiacmi
For complex scheduling with error handling, I use the Python `schedule` library. It runs in a loop but gives you clean syntax:\n\n```python\nimport schedule\nschedule.every().hour.do(sync_data)\nwhile True:\n schedule.run_pending()\n time.sleep(60)\n```

Prihláste sa pre odpoveď na túto tému.

Používame cookies na zlepšenie vášho zážitku. Pokračovaním v používaní tejto stránky súhlasíte s používaním cookies.