Sunday 15 July 2012

python - pyOpenSSL + HTTPServer: Request doesn't complete until all processes finish -


I immediately want to return a message and be able to respond to GET and then start a process to run it my background and finish a task it works fine with BaseHTTPServer.HTTPServer and expand BaseHTTPRequestHandler However, when I follow the instructions to add SSL to the server do not then sent to react when finished Sbproses Happens. It is believed that Firefox receives it, which receives it, and double checks with firebugs, it appears that nothing is sent until the sub-process is completed I tested in Chrome and the same result saw. Code below; I am at a disadvantage for how to continue debugging

  class SecureHTTPServer (HTTPServer):. Def __init __ (self, SERVER_ADDRESS, HandlerClass): BaseServer .__ init __ (self, SERVER_ADDRESS, HandlerClass) ctx = SSL.Context (SSL.SSLv3_METHOD) ctx.use_privatekey_file (SSL_CERT) ctx.use_certificate_file (SSL_CERT) self.socket = SSL .connection (ctx, socket.socket (self.address_family, self.socket_type)) self.server_bind () self server_activate () def Shutdown_request (self, request): request.shutdown () class RecordingHandler (BaseHTTPRequestHandler): def setup (self): self.connection = self.request self.rfile = socket._fileobject (self.request, "rb" , self.rbufsize) self.wfile = socket._fileobject (self.request, "WB", self.wbufsize) do_GET (self) def: key = 'ABC' P = process (target = Some_func, args = (key, )) # Some_funx takes 15 seconds to complete, and it logs its progress so that it becomes clear that the response is sent only after the completion of some_function Minister is. P.daemon = True p.start () self.send_response (200) self.end_headers () self.wfile.write ( 'recording key + key) def run (): try: server = SecureHTTPServer ((' ', 8080), recording handler) Waiting for input on print 8080. 'Server.serve_forever () In addition to KeyboardInterrupt: Print' received keyboards, in the middle, exit '. Server.shutdown ()    

Apparently leave me, restart and try I've been talking again:

  Import BaseHTTPServer, SimpleHTTPServer import ssl httpd = BaseHTTPServer.HTTPServer (('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler) httpd.socket = ssl .wrap_socket (httpd.socket, certfile = 'Path / to / localhost.pem', server_side = true) httpd.serve_forever ()   

I just do not know what went wrong in the previous installation Was, but it works just fine.

No comments:

Post a Comment