Skip to content

Commit

Permalink
Added an option for specifying a callback function
Browse files Browse the repository at this point in the history
If you pass a function to `eel.start()` with parameter name `callback`, that function is called when the user closes the window.

This can be used to prevent the Python script from staying alive when running background threads
  • Loading branch information
eliaperantoni committed Jun 3, 2018
1 parent 00d3f5a commit bb86dbb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'port': 8000,
'chromeFlags': []
}
_callback = lambda: None

# Public functions

Expand Down Expand Up @@ -85,11 +86,15 @@ def init(path):


def start(*start_urls, **kwargs):
global _callback

block = kwargs.pop('block', True)
options = kwargs.pop('options', {})
size = kwargs.pop('size', None)
position = kwargs.pop('position', None)
geometry = kwargs.pop('geometry', {})

_callback = kwargs.pop('callback', lambda: None)

for k, v in list(_default_options.items()):
if k not in options:
Expand Down Expand Up @@ -256,4 +261,5 @@ def _websocket_close():
# TODO: user definable behavior here
sleep(1.0)
if len(_websockets) == 0:
_callback()
sys.exit()

0 comments on commit bb86dbb

Please sign in to comment.