The Automation Pipeline — Pairing with a Scheduler So It Works at Night Too
Описание и применение
Автоматизация запуска Python‑скрипта в Windows с помощью Task Scheduler, используя .vbs‑обёртку, UTF‑8‑вывод, lock‑файл и state‑файл для предотвращения дублирования и орфан‑процессов.
Задача
Automating a Python script on Windows to run unattended without manual intervention, while avoiding common pitfalls such as console flashes, encoding errors, orphan processes, and silent failures.
Результат
The pipeline runs unattended, produces artifacts, surfaces failures, avoids orphan processes, and prevents duplicate outputs.
Рабочий процесс
- 1. Create a .vbs wrapper that runs the Python script with no window and waits for completion.
2. Ensure the wrapper exits with the script’s return code using
WScript.Quit rc. 3. Use a launcherrun.pyto set UTF‑8 stdout and invoke the main script viasubprocess.run. 4. Verify the scheduler entry contains no Korean characters. 5. Implement a lock file (collect.lock) and afinallyblock to release it. 6. Add a state file (SEEN) to track processed items and avoid duplicates. 7. Test the task manually after registration and confirm the output artifact. 8. Check that failures (e.g., network disconnect) appear in the report. 9. Verify no orphan processes after several runs. 10. Schedule the task at a desired interval (daily recommended).
Доказательства
If the scheduler runs python or a .bat directly, a black window pops up every few minutes and interrupts your work.
The proper approach is a wscript + .vbs wrapper.
If you leave this out, the script can fail every single day while the scheduler's history records success.
When unattended execution fails repeatedly, zombie processes pile up, and one day the whole computer slows down.
- Дата записи: 2026-09-15T16:02:02.191Z