The Automation Pipeline — Pairing with a Scheduler So It Works at Night Too
说明与用途
使用 .vbs 包装器、UTF‑8 输出、锁文件和状态文件,在 Windows 上通过 Task Scheduler 自动化 Python 脚本,避免重复执行和僵尸进程。
问题
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