SIGCHLD, fork, listen
D'Arcy J.M. Cain
darcy at vex.net
Thu Sep 23 09:14:06 EDT 1999
bill <bill at rfa.org> wrote:
> I'm trying to set up a fairly "simple"
> server that listens for a socket connection,
> forks off a process and goes back to listening.
> This works fine for multiple clients, except
> I get zombies. I try redefining SIGCHLD as
> SIG_IGN, but this doesn't work (as apparently
> is what's expected under POSIX). I then
> try redefining it with my own function that
> includes a WAIT. Fine, except "listen"
> doesn't get signalled when the child process
> dies, only when the next socket connection
> occurs. (which could be hours later, not
> good).
How are you creating your server? Are you using SocketServer? This
supposedly does what you want. Here is a simple echo server using it.
---------------------------- echod ----------------------------
#! /usr/bin/env python
HOST = ''
PORT = 51000
from SocketServer import *
class echohandler(ForkingMixIn, StreamRequestHandler):
def handle(self):
self.wfile.write(self.rfile.readline(16384))
if __name__=='__main__':
from socket import *
server = TCPServer((HOST, PORT), echohandler)
server.serve_forever()
---------------------------------------------------------------
However, on a simple test, I find that this doesn't actually fork.
If someone can suggest why this doesn't fork, you should be able
to use this instead. Note I tried reversing the order of the inherited
classes with no difference.
The simple test, btw, is to telnet to the port from two windows and type
a line into the second one then the first. The second one doesn't echo
until I type in something into the first session.
--
D'Arcy J.M. Cain <darcy at caingang.com> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
More information about the Python-list
mailing list