Skip to content

Commit

Permalink
Merge pull request #337 from samuelhwilliams/delay-shutdown
Browse files Browse the repository at this point in the history
Shut down the eel server less aggressively
  • Loading branch information
samuelhwilliams authored Jun 28, 2020
2 parents 0684eb5 + 9ea4024 commit 5692f70
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions eel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from builtins import range
from io import open

from gevent.threading import Timer
import gevent as gvt
import json as jsn
import bottle as btl
Expand All @@ -25,6 +26,7 @@
_js_functions = []
_mock_queue = []
_mock_queue_done = set()
_shutdown = None

# The maximum time (in milliseconds) that Python will try to retrieve a return value for functions executing in JS
# Can be overridden through `eel.init` with the kwarg `js_result_timeout` (default: 10000)
Expand Down Expand Up @@ -326,17 +328,24 @@ def _expose(name, function):
_exposed_functions[name] = function


def _detect_shutdown():
if len(_websockets) == 0:
sys.exit()


def _websocket_close(page):
global _shutdown

close_callback = _start_args.get('close_callback')

if close_callback is not None:
sockets = [p for _, p in _websockets]
close_callback(page, sockets)
else:
# Default behaviour - wait 1s, then quit if all sockets are closed
sleep(1.0)
if len(_websockets) == 0:
sys.exit()
if _shutdown:
_shutdown.kill()

_shutdown = gvt.spawn_later(1.0, _detect_shutdown)


def _set_response_headers(response):
Expand Down

3 comments on commit 5692f70

@gaetan1903
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I change this 1.0 to 5.0 for example?

@samuelhwilliams
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make this configurable, but at the moment it's not. Happy to accept a PR that makes this change :)

@gaetan1903
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll send a pull request to make it configurable

Please sign in to comment.