Forums

Keep script running after closing console

Hi,

I tried to use NOHUP for this purpose but it cannot find the command.

How can I keep my scripts running?

Thanks!

Scripts should continue running if you close the tab without exiting (Ctrl-D or exit) the shell. Then you can reconnect to it later.

One thing to keep in mind, though, is that they won't necessarily run forever -- sometimes we have to reboot console servers for maintenance, for example. If you need a script that's definitely running forever, then this help page has some hints.

Thanks a lot, looks easy!

No problem, glad to help!

Actually... where it says

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

Is my task supposed to be my .py name?

Can I somehow change my_long_running_process() with the actual script, so that it's started again?

Sorry about this newbie questions.

You can put anything you want in the "my-task-name" bit, so long as it's unique amongst your scripts. So you could have two or three long-running scripts, each of which had its own lock.

And sure, you can put the whole script where it says

my_long_running_process()

Hey guys, I tried implementing the mentioned "long running tasks" script example and it seems that my scirpt is always terminating after the same time, at about 350 minutes. Is this because of your maintaince acticity or is my script failing itself? Could it be of memory issues?

Schedule log says:

/bin/bash: line 1: 22451 Killed python /bin/run_scheduled_task.py /home/paulhaedicke/service/watchdog.py

2016-03-22 04:08:08 -- Completed task, took 21662.00 seconds, return code was 137.

Regards,

Paul

Hi Paul, yes, we kill tasks after a certain amount of time. Currently the cutoffs are 1 hour for free users and 6 hours for paying users, but we're gradually increasing those as we scale up the service.

For now, probably best to switch to using an hourly task?

Hello harry, ok great, now I understand. I'm using right now an hourly task to check and in case restart my script. However this produced a gap of about 1 hour every 6 hours. So I'm thinking of running two scheduled taks to reduce this time. Another option would be that the scipt after several hours kills itself to shortly restart again. What do you think about that solution? Anyway thanks for your great support and very quick answers!!!!

Just jumping in here while Harry's busy -- that sounds like it should work!

Hey guys, & what if I have not an ordinary couple of lines as a script, but a chatbot for instance? usually, I run it like this in the console: python3 MyBot.py. There is no one main function, that I can run to run the whole bot. Is there a way to run .py file continuously?

three options:

  • you can put the whole of mybot.py into a main function. just put def main(): at the top and indent everything else in the file

  • or you can just add the contents of your mybot.py script into the scheduled task file that has the locking code

  • or you can add the locking code to the top of your mybot.py script and run that as the scheduled task.

Sorry for the maybe dumb question, but I am trying to run instabot.py here and while I am succeeding at it I am not able to keep it running. I have a paid account and I am trying to set up the script as described in the above linked help page. So, I created a test.py file containing the code listed in such help page and at the end I called the bot function. Everything is fine so far. Now, I need to create the recurring task that should start this test.py every hour via the Tasks menu of PA. What should I put as lock_id = "my-username.my-task-name"? The bot script name or the test.py itself?

that's just anything that is unique. so eg: it could be Juushichi-test