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()
评论列表
文章目录