Forums

Why do scheduled tasks hang when they take too long to finish?

Hi all,

Quite often in a month, In receive a notification about failures of scheduled tasks to launch because of the accumulation of them in the list of tasks currently running. And when consulting the log, I see that they seem to hang (or freeze) in the middle of the program without any reason.

The frozen scripts are neither killed by the server daemon nor in an deadlock/pitfall situation (I run the same code on my computer and it never has this problem even after 16 days of work). Can someone explain me this behaviour of the task scheduler?

One possibility is that they're printing out a lot of stuff -- that can cause things to lock up. Might that be it?

Yes they print a lot of stuff, but not all the printed stuff is stored... So why does that cause things to lock up?

It's a bug on our side :-( If you try removing some prints, it should start working again.

Ok, got it : I'll try to overwrite all the printing function to a null function... But then would you think that things that take quite a while to finish (say 30 min.) will continue running without freezing? If so, that'd be fine!

Thanks you for all your answers, and continue improving PythonAnywhere :)

If you need any of the data you were printing out, the Python logging module is quite functional...☺

Yup, tasks that take 30 minutes should be absolutely fine. And +1 to a2j's suggestion of using the Python logging module and logging to a file somewhere in your file space. It can be a bit of a pain to configure, though, so I definitely recommend taking a look at this tutorial if you've not used it before.

@giles: Agreed. It is foreign if someone is new to it.

@radotranonkala: The link from Giles is great and part of the official docs. It's listed at the top of the link from me in addition to an advanced tutorial and a Logging Cookbook for examples. Oh, and one more difference. My link is to the Python 3 docs, so you'll need to change the drop down on the upper left if you'd prefer the Python 2 doc version.