As far as I can tell, you don't need python-rq
at all. A message queue is typically used for communication in a distributed system, which is way overkill for somebody that just wants to run a long-running script on a remote server. You could skip the rqworker
and run your script directly. Add if __name__=='__main__': test2()
to your action_test.py
script, then you can run the script from the command line:
python test_action.py
As you point out, when you close your SSH session, your script also gets killed. That's because of some Unix/Linux magic called "signals": the system sends a "hangup" signal to your job, also known as SIGHUP
. Martin mentioned nohup
already and that's a workable answer (e.g. nohup python test_action.py
) but it's a bit complicated for a beginner who just wants to run a long script.
A simpler solution for you is to use screen
. Screen creates a virtual terminal that lets you disconnect from a shell and reconnect later. If you have screen installed, just run screen
and it will create a new virtual terminal for you. Now run your program as normal: python test_action.py
. Once it gets started, type Ctrl+A and then D to disconnect. Now you can disconnect your SSH session but the job will keep running in the virtual terminal as if nothing happened. Later on, you can SSH back to the server and type screen -r
to resume using that terminal.
More info here: https://unix.stackexchange.com/questions/24658/nohup-vs-screen