浏览器打开位置服务器,如何启动http服务器,然后打开web浏览器?
我正在嘗試: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"
如果我取消對webbrowser行的注釋,瀏覽器將不會停止打開新窗口。為什么?在
我仍然不太了解多處理模塊,但是像這樣的東西應該很簡單。這是怎么做到的?在
編輯:
似乎工作得很好。在
但我想知道如何向服務器發送SystemExit信號。更好的方法?在
總結
以上是生活随笔為你收集整理的浏览器打开位置服务器,如何启动http服务器,然后打开web浏览器?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: task文件服务器无法输入,Win10系
- 下一篇: ie内核浏览器_[正式版下载] 微软全新