I have a simple server that extends SimpleHTTPRequestHandler
If I start and stop it without any requests to the server, I can restart the backup file on the same port without any problems.
When you start netstat, it looks like this:
sam@hersheezy : server $ sudo netstat -na --program | grep 8001
tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 23392 / python
After the request is made, netstat looks like this (even after the request is completed):
sam@hersheezy : server $ sudo netstat -na --program | grep 8001
tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 23392 / python
tcp 0 0 127.0.0.1:8001 127.0.0.1:48659 TIME_WAIT -
Then I kill the server using Cc, and netstat looks like this (at this moment I can not restart the server because the port is already in use):
sudo netstat -na --program | grep 8001
tcp 0 0 127.0.0.1:8001 127.0.0.1:48674 TIME_WAIT -
I obviously do not close something correctly. My code that sends the response is as follows:
""" reply is an object that can be json encoded that is written with a response code 200 """ def send_provider_reply(self, replyobj): try: str_reply = json.dumps(replyobj) self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers()
source share