Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 瓶装水和PyWebView_Python 3.x_Bottle - Fatal编程技术网

Python 3.x 瓶装水和PyWebView

Python 3.x 瓶装水和PyWebView,python-3.x,bottle,Python 3.x,Bottle,我正在尝试在瓶子里构建一个小应用程序,并想尝试使用pywebview作为查看器。当我运行下面的文件时,我得到了webview窗口的两个实例。第一个显示页面,第二个显示旋转滚轮光标。我相信,关闭第二个窗口是关闭web服务器,但不是终止线程 为什么会出现两个窗口 import sys import threading from bottle import Bottle, ServerAdapter import webview class MyWSGIRefServer(ServerAdapt

我正在尝试在瓶子里构建一个小应用程序,并想尝试使用pywebview作为查看器。当我运行下面的文件时,我得到了webview窗口的两个实例。第一个显示页面,第二个显示旋转滚轮光标。我相信,关闭第二个窗口是关闭web服务器,但不是终止线程

为什么会出现两个窗口

import sys
import threading

from bottle import Bottle, ServerAdapter
import webview


class MyWSGIRefServer(ServerAdapter):
    server = None

    def run(self, handler):
        from wsgiref.simple_server import make_server, WSGIRequestHandler
        if self.quiet:
            class QuietHandler(WSGIRequestHandler):
                def log_request(*args, **kw): pass
            self.options['handler_class'] = QuietHandler
        self.server = make_server(self.host, self.port, handler, **self.options)
        self.server.serve_forever()

    def stop(self):
        # self.server.server_close() <--- alternative but causes bad fd exception
        self.server.shutdown()

app = Bottle()
listen_addr = 'localhost'
listen_port = 8080

server = MyWSGIRefServer(host='localhost', port=8080)

@app.route('/')
def hello():
    return "Hello World!"




def start_server():
    app.run(server=server, reloader=True)


try:
    print(threading.enumerate())
    serverthread = threading.Thread(target=start_server)
    serverthread.daemon = True
    print("starting web server")
    serverthread.start()
    print("starting webview")
    webview.create_window('bottle test', "http://localhost:8080/")
    print("webview closed. closing server")

    sys.exit()
    server.stop()
except Exception as ex:
    print(ex)
问题在于运行服务器时使用了reloader=True。将此设置为False可防止出现第二个窗口