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

Commit 57b951f

Browse files
Merge branch 'master' into master
2 parents 2e55638 + 421c348 commit 57b951f

File tree

5 files changed

+419
-876
lines changed

5 files changed

+419
-876
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change log
22

3-
### v0.13.0
3+
### v0.13.2
4+
* Add `default_path` start arg to define a default file to retrieve when hitting the root URL.
5+
6+
### v0.13.1
7+
* Shut down the Eel server less aggressively when websockets get closed (#337)
8+
9+
## v0.13.0
410
* Drop support for Python versions below 3.6
511
* Add `jinja2` as an extra for pip installation, e.g. `pip install eel[jinja2]`.
612
* Bump dependencies in examples to dismiss github security notices. We probably want to set up a policy to ignore example dependencies as they shouldn't be considered a source of vulnerabilities.

eel/__init__.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import traceback
33
from io import open
44

5+
from gevent.threading import Timer
56
import gevent as gvt
67
import json as jsn
78
import bottle as btl
@@ -26,6 +27,7 @@
2627
_js_functions = []
2728
_mock_queue = []
2829
_mock_queue_done = set()
30+
_shutdown = None
2931

3032
# The maximum time (in milliseconds) that Python will try to retrieve a return value for functions executing in JS
3133
# Can be overridden through `eel.init` with the kwarg `js_result_timeout` (default: 10000)
@@ -46,6 +48,7 @@
4648
'app_mode': True, # (Chrome specific option)
4749
'all_interfaces': False, # Allow bottle server to listen for connections on all interfaces
4850
'disable_cache': True, # Sets the no-store response header when serving assets
51+
'default_path': 'index.html', # The default file to retrieve for the root URL
4952
'app': btl.default_app(), # Allows passing in a custom Bottle instance, e.g. with middleware
5053
}
5154

@@ -192,6 +195,9 @@ def _eel():
192195
_set_response_headers(btl.response)
193196
return page
194197

198+
def _root():
199+
return _static(_start_args['default_path'])
200+
195201
def _static(path):
196202
response = None
197203
if 'jinja_env' in _start_args and 'jinja_templates' in _start_args:
@@ -235,6 +241,7 @@ def _websocket(ws):
235241

236242
BOTTLE_ROUTES = {
237243
"/eel.js": (_eel, dict()),
244+
"/": (_root, dict()),
238245
"/<path:path>": (_static, dict()),
239246
"/eel": (_websocket, dict(apply=[wbs.websocket]))
240247
}
@@ -343,17 +350,24 @@ def _expose(name, function):
343350
_exposed_functions[name] = function
344351

345352

353+
def _detect_shutdown():
354+
if len(_websockets) == 0:
355+
sys.exit()
356+
357+
346358
def _websocket_close(page):
359+
global _shutdown
360+
347361
close_callback = _start_args.get('close_callback')
348362

349363
if close_callback is not None:
350364
sockets = [p for _, p in _websockets]
351365
close_callback(page, sockets)
352366
else:
353-
# Default behaviour - wait 1s, then quit if all sockets are closed
354-
sleep(1.0)
355-
if len(_websockets) == 0:
356-
sys.exit()
367+
if _shutdown:
368+
_shutdown.kill()
369+
370+
_shutdown = gvt.spawn_later(1.0, _detect_shutdown)
357371

358372

359373
def _set_response_headers(response):

0 commit comments

Comments
 (0)