diff --git a/README.md b/README.md index a445cc84..0cf08d25 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ As of Eel v0.12.0, the following options are available to `start()`: - **close_callback**, a lambda or function that is called when a websocket to a window closes (i.e. when the user closes the window). It should take two arguments; a string which is the relative path of the page that just closed, and a list of other websockets that are still open. *Default: `None`* - **app**, an instance of Bottle which will be used rather than creating a fresh one. This can be used to install middleware on the instance before starting eel, e.g. for session management, authentication, etc. + - **shutdown_delay**, timer configurable for Eel's shutdown detection mechanism, whereby when any websocket closes, it waits `shutdown_delay` seconds, and then checks if there are now any websocket connections. If not, then Eel closes. In case the user has closed the browser and wants to exit the program. Default: `1.0` diff --git a/eel/__init__.py b/eel/__init__.py index f3df71bb..effe4228 100644 --- a/eel/__init__.py +++ b/eel/__init__.py @@ -51,6 +51,7 @@ 'disable_cache': True, # Sets the no-store response header when serving assets 'default_path': 'index.html', # The default file to retrieve for the root URL 'app': btl.default_app(), # Allows passing in a custom Bottle instance, e.g. with middleware + 'shutdown_delay': 1.0 # how long to wait after a websocket closes before detecting complete shutdown } # == Temporary (suppressable) error message to inform users of breaking API change for v1.0.0 === @@ -153,6 +154,10 @@ def start(*start_urls, **kwargs): _start_args['jinja_env'] = Environment(loader=FileSystemLoader(templates_path), autoescape=select_autoescape(['html', 'xml'])) + # verify shutdown_delay is correct value + if not isinstance(_start_args['shutdown_delay'], (int, float)): + raise ValueError("`shutdown_delay` must be a number, \ + got a {}".format(type(_start_args['shutdown_delay'])) # Launch the browser to the starting URLs show(*start_urls) @@ -380,7 +385,7 @@ def _websocket_close(page): if _shutdown: _shutdown.kill() - _shutdown = gvt.spawn_later(1.0, _detect_shutdown) + _shutdown = gvt.spawn_later(_start_args['shutdown_delay'], _detect_shutdown) def _set_response_headers(response):