我正在尝试:
import multiprocessing
from wsgiref.simple_server import make_server
import webbrowser
import time
def application(environ, start_response):
start_response("200 OK", [("Content-Type", "text/plain")])
return ["Hello!"]
class Server(multiprocessing.Process):
def run(self):
print "HTTP Server starts."
server = make_server(host = "127.0.0.1",
port = 88,
app = application)
try:
server.serve_forever()
except (KeyboardInterrupt, SystemExit):
print "HTTP Server stopped."
raise
httpd = Server()
httpd.start()
#webbrowser.open("http://127.0.0.1:88")
time.sleep(3)
httpd.terminate()
httpd.join()
print "End"
如果我取消注释Web浏览器行,则浏览器将不会停止打开新窗口。为什么?
我仍然不太了解多处理模块,但是这样的事情应该很简单。这是怎么做的?
相关分类