欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 前端技术 > HTML >内容正文

HTML

浏览器打开位置服务器,如何启动http服务器,然后打开web浏览器?

发布时间:2024/1/23 HTML 36 豆豆
生活随笔 收集整理的这篇文章主要介绍了 浏览器打开位置服务器,如何启动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浏览器?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。