I spent my lunch hacking a dirty remote shell in python.
signal.signal(signal.SIGCHLD, reaper) # ... while True: client, who = server.accept()
Blam ! When the server process receives SIGCHLD, accept() is interrupted. So I added a try/except around the accept() :
while True: try: client, who = server.accept() except OSError, e: if e.errno != errno.EINTR: sys.exit(e) else: continue
Re-blam. I didn't paid attention to the previous exception's type. It was socket.error. I though it was a subclass of OSError ... it's not. issubclass(socket.error, OSError) == False. pydoc socket :/
The correct except statement is :
while True: try: client, who = server.accept() except socket.error, e: if e.args[0] != errno.EINTR: sys.exit(e) else: continue
The socket.* error classes are just Exception. It would be nice to turn them into OSError :)