What are some good alternatives to using Task Scheduler for python script automation on Windows?

I work on a team that uses solely windows machines, and I need to automate python scripts for my job. I've been using batch files and scheduling them on Task Scheduler, but I've found that the program is pretty unreliable. What are some better options for accomplishing this?

Posted Jul 9, 2018, 2:47 PM UTC

09
athermop•

Even if you use something other than Task Scheduler, the chances are good you will still have problems because Task Scheduler is not the source of your unreliability. Task Scheduler is a core part of Windows and is used extensively for core Windows services. Nothing about it is unreliable.

6
dhass21•

You can use Ansible and have your tasks defined using it.

2
ericgj•

From your description, Task Scheduler is probably your best option. In my experience it's not that it's unreliable but 1) hard to set up right and 2) hard to debug. It's hard to set up bc the runtime environment is minimal and hard to debug bc it swallows stdout and stderr. It takes some getting used to.

If you are spawning off stuff within another python process (e.g. an event loop or listening on a socket), you could take a look at APScheduler.

2
data_analistOP•

Yeah I think the consensus from this post is that I'm probably not setting it up correctly. To give you an idea, I have a daily script that works 80% of the time, but the other 20% it'll fail with a 0x1 error that I haven't been able to debug. I've always assumed that it's just because task scheduler is unreliable because that's what I've been told previously. Do you have any suggestions for resources?

1
cracknwhip•

Use the logging module and log everything relevant to file.

Or, run your task manually in the terminal with a while true loop + sleep and print all errors and steps to see when it/how it fails. Then fix it and put it back on the scheduler.

3
robvas•

Try VisualCron out

1

You could code the file to wait until past a certain time inside the python file itself? Kinda hacky, but it works reliably

1
evolving6000•

Testing out Luigi and Airflow currently. Just wanted to mention.

1
[deleted]•

[deleted]

-4
Kosmiche•

No.

2
[deleted]•

[deleted]

1