Forums

Scheduled script with while loop still executing after deletion

Hey there,

I just experimented with a simple Twitter bot and the Schedule Task functionality of pythonanywhere.

Within my script I had a 'while True' loop with a sleep intervall of 300 seconds.

I deleted the Schedule Task, even modified the code but the script is still running (it still posts Tweets).

What can do to stop the script from running?

I suppose it should have stopped by now? Since it was still running a process killing the task did not finish it -- there's a "Fetch process list" button in the "Running tasks" section in the Tasks page which shows processes actually run by the tasks. We have a script that kills those processes after few hours on free accounts, so I suppose that it stopped your bot but it happened some time after you stopped the task which could be confusing.

Indeed, thanks! I discovered this "Running tasks" section a few minutes after my post and killed the task. Thanks anyway!

OK, glad you figured that out!

Quick question regarding your script: I scheduled another task with a while True time of 2 hours. The first actions were performed around 08.30 (the initial one) and around 10.30 (the first one in the while loop). But it didn't perform an action at 12:30. The log says "/bin/bash: line 1: <number> Killed". Is this the script you mentioned? Or is it me?

It's likely to have been our script, yes. To give more detail to what @pafk said -- tasks in free accounts will run for at least two hours, but after that point they may be killed. The process that does that runs periodically, so you might get more than two hours, but you shouldn't get less.

Thanks for your response. So I guess I need to upgrade my Account, right? Will the 5$ plan enable me to circumvent that restriction? Also, will the 5$ plan enable me to schedule recurring tasks on a two hour level (not sure about the intervals in that feature)?.

Yes to both of your questions. Tasks for paid accounts will only be terminated after 12 hours and you can schedule hourly tasks with a paid account. That is true for all paid accounts.

Can I define the task intervals by myself or do you have predefined ones, e.g. hourly, daily, weekly? My script should run every two hours.

You need to make them hourly and make them exit early on odd or even hours (in the code or wrap your code inside some custom runner script).