也许使用线程?将服务器设置与主线程或browsweropen分开放置,如下所示:
import threadingimport webbrowserdef start_browser(server_ready_event, url): print "[Browser Thread] Waiting for server to start" server_ready_event.wait() print "[Browser Thread] Opening browser" webbrowser.open(url)url = "someurl"server_ready = threading.Event()browser_thread = threading.Thread(target=start_browser, args=(server_ready, url))browser_thread.start()print "[Main Thread] Starting server"httpd = make_server('', 80, server)print "[Main Thread] Server started"server_ready.set()httpd.serve_forever()browser_thread.join()
(将服务器设置放入主线程中可以捕获我认为的ctrl + c事件)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)