flask_socket_helpers.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Cozmo-Explorer-Tool 作者: GrinningHermit 项目源码 文件源码
def _delayed_open_web_browser(url, delay, new=0, autoraise=True, specific_browser=None):
    """
    Spawn a thread and call sleep_and_open_web_browser from within it so that main thread can keep executing at the
    same time. Insert a small sleep before opening a web-browser
    this gives Flask a chance to start running before the browser starts requesting data from Flask.
    """

    def _sleep_and_open_web_browser(url, delay, new, autoraise, specific_browser):
        sleep(delay)
        browser = webbrowser

        # E.g. On OSX the following would use the Chrome browser app from that location
        # specific_browser = 'open -a /Applications/Google\ Chrome.app %s'
        if specific_browser:
            browser = webbrowser.get(specific_browser)

        browser.open(url, new=new, autoraise=autoraise)

    thread = Thread(target=_sleep_and_open_web_browser,
                    kwargs=dict(url=url, new=new, autoraise=autoraise, delay=delay, specific_browser=specific_browser))
    thread.daemon = True # Force to quit on main quitting
    thread.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号