简体   繁体   中英

Windows Task Scheduler, python script, code 2147942401

Having some odd trouble scheduling a task for a python script. Specifically this script and the problem is intermittent, which made me hesitant to pose the question because I'm very confused. I have other scheduled scripts that run fine. This one is the only one modifying a SQLite database though.

I call the script daily, I've done this several ways with the same result. I finally settled on Action "start a program", Program/script: "python" (it is in my path, but i've also directly called py.exe and pyw.exe, with the same result). Add arguments: "scriptname.py". Start in "location of script and database file" which the account I'm using in the scheduler has full read/write/execute access to. And I've instructed this to work whether or not the user is logged in.

I use this same operation for several other scripts and they are fine, this one just doesn't work sometimes. It always runs, but every few days it exits with code 2147942401 instead of 0. On these days the database is not updated, so I suppose it had trouble writing? I'm not sure. It seems this error code in windows is associated with invalid function, but I can manually run the script and everything is fine. And half the days (not exactly half, seemingly randomly), it doesn't work. This never happened until about 3 weeks ago. Nothing changed that I'm aware of, everything has been running fine for months and then bam, exit code 2147942401. It did it several days in a row, and then no problems for a few days. Never a problem running task (or script) manually. It is set to run with highest privileges.

Anyone seen anything like this?

Turns out it was my script breaking. This is the error code (oddly enough there's not much documentation) you get when your python program ends with code -1 (exits without finishing properly or has some unhandled exception). It was intermittent because I was checking a web page and sometimes that web server just didn't respond for any number of reason. Leaving this here for posterity. If you get this error code in task scheduler, write some logging and error handling into your script because it may be a weird problem you didn't think of.

我在这里遇到了同样的错误,但不知道如何调试它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM