Forums

Long Running Task Explaination

Hi All,

Would someone mind clarifying the set up of a long running task?

https://www.pythonanywhere.com/wiki/LongRunningTasks

Am I adding this code as the actual task? Sorry confused :)

Also...the .my-task-name is what exactly?

lock_id = "my-username.my-task-name"

The task name is anything you like - simplest would be just the name of your app, e.g.

lock_id = "graingerkid.app1"

Using the prefix "graingerkid." as recommended should be enough to ensure that the name is unique (if everyone follows this convention).

So that is nothing specific, it's just to distinguish it?

So do I set that script going using my scheduled task and just run my 'long running' script using that one?

Exactly. The code basically just says "if this script is already running on this machine, exit immediately". Because all of your scheduled tasks are currently guaranteed to run on the same machine, then this means that it just restarts the script if it has exited for some reason.

Hello Guys I have the same question but I don't fully understand. i have my script test.py while true ping 4.2.2.2 wait 60s

should I include the code from https://help.pythonanywhere.com/pages/LongRunningTasks into my script? or this is an independent script? if so, How do I relate both scripts.

You either need to put your code into a function that you can import into the long running task script or you can use the long running task script and copy your code into it.

now I see the identifier "my-username.my-task-name" is shared among all users in the machine, that explains why using that example id always failed on scheduled tasks

That identifier is an identifier. It's up to you to give it a value that is unique to you and your application.