This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ryan003
Recipients ryan003
Date 2009-04-07.00:30:46
SpamBayes Score 3.13543e-08
Marked as misclassified No
Message-id <1239064250.04.0.401358738839.issue5715@psf.upfronthosting.co.za>
In-reply-to
Content
During implement simple forking TCP server, I got the hang-up child
process binding listen socket which caused parent(listen/accept)
restarting failed. (port in use)

Because child process does something with connected socket, there's no
need to bind listen socket in child process.
(finish_request() calls RequestHandlerClass with connected socket(=request))

Simply add self.socket.close() in the beginning of forked child process.


SocketServer.ForkingMixIn :
    def process_request(self, request, client_address):
        """Fork a new subprocess to process the request."""
        self.collect_children()
        pid = os.fork()
        if pid:
            # Parent process
            if self.active_children is None:
                self.active_children = []
            self.active_children.append(pid)
            self.close_request(request)
            return
        else:
            # Child process.
            # This must never return, hence os._exit()!
            self.socket.close() # close parent's listen socket in child
            try:
                self.finish_request(request, client_address)
                os._exit(0)
            except:
                try:
                    self.handle_error(request, client_address)
                finally:
                    os._exit(1)
History
Date User Action Args
2009-04-07 00:30:50ryan003setrecipients: + ryan003
2009-04-07 00:30:50ryan003setmessageid: <1239064250.04.0.401358738839.issue5715@psf.upfronthosting.co.za>
2009-04-07 00:30:48ryan003linkissue5715 messages
2009-04-07 00:30:46ryan003create