I have my gameServer.py script running remotely through PuTTy.
gameServer.py looks like this:
while True : (( listen for packets )) (( send all packets to all clients ))
WHEN I execute the script normally:
./gameServer.py
It works perfectly but the terminal is tied up. Naturally quitting PuTTy terminates my script.
I want to be able to close PuTTY and just have this script run perpetually so I tried:
./gameServer.py &
But that actually does not work and I don't understand why. First of all its not receiving or sending any packets when run in that &
mode, second of all it will go "+ Stopped" whenever I type enter or ANYTHING into the console.
I don't see why it would be stopping, but try
This should cause gameServer.py to ignore the hangup signal when you disconnect PuTTY
Try putting it in the background with the command: bg
You can change your process to be a daemon, then you can detouch your tty without having it killed:
and in your script simple invoke this function
You can look at this ActiveState recipe for more about the double-fork mechanism and more precise implementation.
Another way to log off and leave jobs running is with the "
disown <jobid>
" command. It allows you to unbind jobs from the current login session, so you can logoff.This isn't aimed at answering your python problem, wouldn't have a clue where to start with that, but a temporary workaround / useful utility is called
screen
yum install screen
orapt-get install screen
if you're using either Debian/Ubuntu or Redhat/Centos/Fedora will install it. Screen provides you with a shell session that you can detach from and re-attach from without having to maintain a connection. I pretty much use it on any box I'm connected to because if I get disconnected I don't cut off potentially damaging work in it's flow.just run
screen
to spawn a new session, run your command and then press ctrl+a and then d (keep control held down for both letters) To reconnect, runscreen -dr
from the command line and your screen session will attach itself to your current connection.