python - Gevent,http/cgi non blocking server -


address = ( '127.0.0.1', dConfig.cgiport) handler = CGIHTTPServer.CGIHTTPRequestHandler handler.cgi_directories = [ '/ cgi-bin'] self.logger.info (% str (starting http server on port "port% s ")) httpd = BaseHTTPServer.HTTPServer (address, handler) httpd.serve_forever () def work (self): self.runNumber = 0, while it is true: self.logger.info (" count:% s "% str ( self.runNumber)) Self.runNumber + = 1 time.sleep (1)

I want to run a job waiting for http and cgi requests, requests Handle it and then continue the job method. Is it possible to use the gadget (and how), or do I need to use threading?

i.e. I want to run both the concurrent functions without creating threads

This solution works for me.

  • Import Monkey:

         
  • can add and run this method:

      def (self) Run: jobs = [gevent.spawn (self.server), gevent.spawn (self.job) ] Gevent.joinall (task)  

Please try it in your program.


Comments