0
I've asked this question more or less before on stackoverflow and believed it to be solved (hence accepted the answer) but it turns out it wasnt solved. :-(
In simple terms, I've written a python script which just outputs text constantly to stdout, thats all it does 24/7. I've linked it to this xinetd file
service myservice { instances = 1 port = 887 socket_type = stream type = UNLISTED wait = no user = nobody server = /usr/local/bin/myscript.py only_from = 127.0.0.1 192.168.1.2 disable = no max_load = 5.0 nice = 5 per_source = 1 }
This works fine in as much as when a client connects it starts spewing out text on their console. The problem is when the client disconnects, the process launched stays open, blocking the port. There is only one client allowed (instances = 1) but this can occur when the client reboots while connected.
Previously I thought this was because the python script was ignoring kill signals (which it was) but with this fixed, the same behaviour is observed. To clarify, kill -1 etc is now happily observed by the python script.
I'm assuming this is a xinetd issue and fairly simple to fix ?
is this from solid experience ? - because as far as i can tell there no way of doing that from the python script (maybe there is)? - it just spews out output constantly, similar to the "yes" bash command. – Sirex – 2010-09-17T13:52:00.830
@Sirex:
sys.stdin
is tied to the TCP socket, and if the socket is closedsys.stdin.write
will fail. The same applies to any language: you can't write to a closed socket. – user1686 – 2010-09-17T14:04:07.467ok, ill leave this question open as im going away for 2 weeks, but i'll test when i get back. Im not sure if tcp connection is closed cleanly by the client but ill have a look. in the above, you mean sys.stdout and sys.stdout.write, surely ? – Sirex – 2010-09-17T14:41:55.103
@Sirex: I actually meant both
sys.stdin
andsys.stdout
. (Yes, it should've been eitherstdin.read()
orstdout.write()
.) – user1686 – 2010-09-17T14:53:10.507