Threading/Multiprocessing in Python -


i have following code:

import simplehttpserver import socketserver  def http_server():     port = 80     handler = simplehttpserver.simplehttprequesthandler     httpd = socketserver.tcpserver(("", port), handler)     httpd.serve_forever() 

the problem that, because of httpd.serve_forever(), hangs rest of program. i'm assuming use threading run on own thread, rest of program can execute independently of server, i'm not sure how implement this.

simplest way, straight docs:

from threading import thread  t = thread(target=http_server) t.start() 

note thread difficult kill as-is, keyboardinterrupts not propagate random threads you've start()ed. may want set daemon=true or have more sophisticated method shut down.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -