SIGCHLD handle & socket
redjade at my-deja.com
redjade at my-deja.com
Fri Dec 8 02:04:55 EST 2000
I am writing a forking-type server with python.
My plan is:
1) first, open a socket with port 15151
2) if there's a connection request, fork a child
3) child will die after 3 sec of connection establishment.
4) parent should handle SIGCHLD signal so that it make zombie-child
disappear.
5) parent should allow any connection request and should be fork-able.
my code is below
----------------
#!/usr/local/bin/python
import socket, os, signal, time
def handle(signum, frame):
print 'CHILD terminated'
os.waitpid(-1, os.WNOHANG)
HOST = ''
PORT = 15151
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind( (HOST, PORT) )
s.listen(6)
signal.signal(signal.SIGCHLD, handle)
while 1:
(conn, addr) = s.accept()
print 'Connected by', addr
pid = os.fork()
if pid == 0:
s.close()
conn.send('\n\nConnection Established\n\n\n')
time.sleep(3)
conn.close()
os._exit(0)
else:
conn.close()
---------
and error occurred.
$ python rjcall.py
Connected by ('147.46.102.27', 59760)
CHILD terminated
Traceback (most recent call last):
File "rjcall.py", line 19, in ?
(conn, addr) = s.accept()
socket.error: (4, 'Interrupted system call')
I can't figure out what is wrong. i think code above follows basic
c-style forking-type daemon. working environment is python2.0 and
FreeBSD-4.2
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list