How To Deal With Python Basehttpserver Killed,but The Port Is Still Be Occupied?
I use python BaseHTTPServer,it can handle do_GET,do_POST methods,in do_POST method,i execute linux shell using os.system,when i kill the python script,but the listening port still
Solution 1:
File descriptors are inherited by default by child processes, so the socket listening on port 80 is inherited by the command you have launched using your system() call.
To avoid that, you should set the FD_CLOEXEC flag on the listening socket. This can be done by adding (and using) a specific HTTPServer class.
classWebServer(BaseHTTPServer.HTTPServer):def__init__(self, *args, **kwargs):
BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs)
# Set FD_CLOEXEC flag
flags = fcntl.fcntl(self.socket.fileno(), fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(self.socket.fileno(), fcntl.F_SETFD, flags)
Related :
Post a Comment for "How To Deal With Python Basehttpserver Killed,but The Port Is Still Be Occupied?"