Created
March 10, 2013 19:06
-
-
Save athoune/5129923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from multiprocessing import Process, Pipe | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
import SocketServer | |
ROOT = "." | |
def webserver(conn): | |
PORT = 8000 | |
class MyOwnHandler(SimpleHTTPRequestHandler): | |
def translate_path(self, path): | |
global ROOT | |
return ROOT + path.split('?')[0] | |
httpd = SocketServer.TCPServer(("", PORT), MyOwnHandler) | |
conn.send(["starting", PORT]) | |
httpd.serve_forever() | |
if __name__ == '__main__': | |
parent_conn, child_conn = Pipe() | |
p = Process(target=webserver, args=(child_conn,)) | |
p.start() | |
print parent_conn.recv() # prints "[42, None, 'hello']" | |
print "muhahhahaha" | |
p.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment