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

Commit 16bdbbf

Browse files
Allow user-configurable timeout on JS execution (#218)
* Allow user-configurable timeout on JS execution Python currently tries for 10 seconds, checking every millisecond, to collect values returned by Javascript functions called via Eel. Some users might expect their functions to execute longer than this, and so it feels reasonable to allow users to configure this to be longer (or shorter) as suits their needs. Resolves #182
1 parent ee87dd2 commit 16bdbbf

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Change log
22

3+
## v0.12.0
4+
* Allow users to override the amount of time Python will wait for Javascript functions running via Eel to run before bailing and returning None.
5+
36
### v0.11.1
47
* Fix the implementation of #203, allowing users to pass their own bottle instances into Eel.
58

6-
### v0.11.0
7-
* Added support for `app` parameter to `eel.start`, which will override the bottle app instance used to run eel. This
9+
## v0.11.0
10+
* Added support for `app` parameter to `eel.start`, which will override the bottle app instance used to run eel. This
811
allows developers to apply any middleware they wish to before handing over to eel.
912
* Disable page caching by default via new `disable_cache` parameter to `eel.start`.
1013
* Add support for listening on all network interfaces via new `all_interfaces` parameter to `eel.start`.
@@ -14,7 +17,7 @@ allows developers to apply any middleware they wish to before handing over to ee
1417
* Fix PyPi project description.
1518

1619
### v0.10.3
17-
* Fix a bug that prevented using Eel without Jinja templating.
20+
* Fix a bug that prevented using Eel without Jinja templating.
1821

1922
### v0.10.2
2023
* Only render templates from within the declared jinja template directory.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Additional options can be passed to `eel.start()` as keyword arguments.
8686

8787
Some of the options include the mode the app is in (e.g. 'chrome'), the port the app runs on, the host name of the app, and adding additional command line flags.
8888

89-
As of Eel v0.11.0, the following options are available to `start()`:
89+
As of Eel v0.12.0, the following options are available to `start()`:
9090
- **mode**, a string specifying what browser to use (e.g. `'chrome'`, `'electron'`, `'edge'`, `'custom'`). Can also be `None` or `False` to not open a window. *Default: `'chrome'`*
9191
- **host**, a string specifying what hostname to use for the Bottle server. *Default: `'localhost'`)*
9292
- **port**, an int specifying what port to use for the Bottle server. Use `0` for port to be picked automatically. *Default: `8000`*.
@@ -221,6 +221,9 @@ While we want to think of our code as comprising a single application, the Pytho
221221

222222
Eel supports two ways of retrieving _return values_ from the other side of the app, which helps keep the code concise.
223223

224+
To prevent hanging forever on the Python side, a timeout has been put in place for trying to retrieve values from
225+
the JavaScript side, which defaults to 10000 milliseconds (10 seconds). This can be changed with the `_js_result_timeout` parameter to `eel.init`. There is no corresponding timeout on the JavaScript side.
226+
224227
#### Callbacks
225228

226229
When you call an exposed function, you can immediately pass a callback function afterwards. This callback will automatically be called asynchrounously with the return value when the function has finished executing on the other side.

eel/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
_mock_queue = []
2626
_mock_queue_done = set()
2727

28+
# The maximum time (in milliseconds) that Python will try to retrieve a return value for functions executing in JS
29+
# Can be overridden through `eel.init` with the kwarg `js_result_timeout` (default: 10000)
30+
_js_result_timeout = 10000
31+
2832
# All start() options must provide a default value and explanation here
2933
_start_args = {
3034
'mode': 'chrome', # What browser is used
@@ -75,8 +79,8 @@ def decorator(function):
7579

7680

7781
def init(path, allowed_extensions=['.js', '.html', '.txt', '.htm',
78-
'.xhtml', '.vue']):
79-
global root_path, _js_functions
82+
'.xhtml', '.vue'], js_result_timeout=10000):
83+
global root_path, _js_functions, _js_result_timeout
8084
root_path = _get_real_path(path)
8185

8286
js_functions = set()
@@ -107,6 +111,8 @@ def init(path, allowed_extensions=['.js', '.html', '.txt', '.htm',
107111
for js_function in _js_functions:
108112
_mock_js_function(js_function)
109113

114+
_js_result_timeout = js_result_timeout
115+
110116

111117
def start(*start_urls, **kwargs):
112118
_start_args.update(kwargs)
@@ -299,13 +305,14 @@ def _js_call(name, args):
299305

300306

301307
def _call_return(call):
308+
global _js_result_timeout
302309
call_id = call['call']
303310

304311
def return_func(callback=None):
305312
if callback is not None:
306313
_call_return_callbacks[call_id] = callback
307314
else:
308-
for w in range(10000):
315+
for w in range(_js_result_timeout):
309316
if call_id in _call_return_values:
310317
return _call_return_values.pop(call_id)
311318
sleep(0.001)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='Eel',
9-
version='0.11.1',
9+
version='0.12.0',
1010
author='Chris Knott',
1111
author_email='chrisknott@hotmail.co.uk',
1212
url='https://github.com/samuelhwilliams/Eel',

0 commit comments

Comments
 (0)