Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit 414b2c3

Browse files
gaetan1903samuelhwilliamsChrisKnott
authored
Add shutdown_delay on the start() function parameter (#529)
* Add time_shutdown on README * Add time_shutdown parameter * Add warning show for incorrect value - Change default if time_shutdown is not correct int or float - Accept string if is a digit * fix typo on README * rename variable, stricter error checking * Update __init__.py fix flake8 warning remplace shortcut `f` not stable on python3.6 by format * Update README.md fix typo * Update __init__.py I think the syntax of this multi-line string was not correct Co-authored-by: Samuel Williams <samuelhwilliams@gmail.com> Co-authored-by: Chris Knott <chrisknott@hotmail.co.uk>
1 parent e2b6aea commit 414b2c3

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ As of Eel v0.12.0, the following options are available to `start()`:
118118
- **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`*
119119
- **app**, an instance of Bottle which will be used rather than creating a fresh one. This can be used to install middleware on the
120120
instance before starting eel, e.g. for session management, authentication, etc.
121+
- **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. By default, the value of **shutdown_delay** is `1.0` second
121122

122123

123124

eel/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
'disable_cache': True, # Sets the no-store response header when serving assets
5252
'default_path': 'index.html', # The default file to retrieve for the root URL
5353
'app': btl.default_app(), # Allows passing in a custom Bottle instance, e.g. with middleware
54+
'shutdown_delay': 1.0 # how long to wait after a websocket closes before detecting complete shutdown
5455
}
5556

5657
# == Temporary (suppressable) error message to inform users of breaking API change for v1.0.0 ===
@@ -153,6 +154,10 @@ def start(*start_urls, **kwargs):
153154
_start_args['jinja_env'] = Environment(loader=FileSystemLoader(templates_path),
154155
autoescape=select_autoescape(['html', 'xml']))
155156

157+
# verify shutdown_delay is correct value
158+
if not isinstance(_start_args['shutdown_delay'], (int, float)):
159+
raise ValueError("`shutdown_delay` must be a number, "\
160+
"got a {}".format(type(_start_args['shutdown_delay'])))
156161

157162
# Launch the browser to the starting URLs
158163
show(*start_urls)
@@ -380,7 +385,7 @@ def _websocket_close(page):
380385
if _shutdown:
381386
_shutdown.kill()
382387

383-
_shutdown = gvt.spawn_later(1.0, _detect_shutdown)
388+
_shutdown = gvt.spawn_later(_start_args['shutdown_delay'], _detect_shutdown)
384389

385390

386391
def _set_response_headers(response):

0 commit comments

Comments
 (0)