Forums

Threads in scheduled tasks and console scripts

According to official answer on threading question https://www.pythonanywhere.com/forums/topic/4438/ it is stated:

"You can't do multi-threaded stuff from web apps, but you can from consoles and in scheduled tasks."

This seems incorrect as I get this error when trying to run script as task that start threads:

RuntimeError: can't start new thread

This is unfortunate as your service fits my needs perfectly but in this case I have a time sensitive task that runs once every day and needs the performance boost of threads (slow network requests and not CPU bound).

So is threads in console and task scripts supposed to work? If not please correct the answer.

There is a limit to how many threads you can start. If you try to create too many, you will get that error in a console or a task.

Thanks, seems like the library I was using did not respect the max thread count I gave it. So I had to chunk the tasks down to 100 in order to get it to work. Thanks for the quick response.