I am creating a ForkingTCPServer to act as a proxy. It handles perfectly fine, but will not release the socket after executing. I have already tried .shutdown()
and .server_close()
but they just cause the program to freeze up. How can I release the socket so that it can be used again?
import SocketServer
import SimpleHTTPServer
import urllib
PORT = 8080
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.copyfile(urllib.urlopen("http://"+self.path[1:]), self.wfile)
httpd = SocketServer.ForkingTCPServer(('', PORT), Proxy)
print "serving at port", PORT
httpd.handle_request()