Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9078

Run task forever in Windows Scheduler, restart if not running

$
0
0

There's a lot of ambiguity about Windows' Task Scheduler ability to receive return codes from scripts. I've found several useful Stack Exchange answers but none of them quite fit my need.

I'm developing for Windows 7.

In the Scheduler I've set-up a task to run upon log-in. All it does is invoke a Python script myscript.py inside a virtual environment. So the action looks like this:

Program: PATH\\TO\\pythonw.exe (pythonw to run in hidden Window)

Arguments: Path\\TO\\myscript.py

Now this myscript.py is a "run-forever script":

bot = Bot(os.getenv("TOKEN", None))bot.run()

run() is basically a polling mechanism that never exists as long as no exceptions occur. That's why when my Task is triggered in Scheduler, it always shows as "running" (is this a good practice?)

Which brings me to the question: How can I tell Task Scheduler to restart this task if it exists? basically, make sure one (and only one) instance of this script is running at all times, no matter what.


Viewing all articles
Browse latest Browse all 9078

Trending Articles