This repository was archived by the owner on Jun 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from builtins import range
22from io import open
33
4+ from gevent .threading import Timer
45import gevent as gvt
56import json as jsn
67import bottle as btl
2526_js_functions = []
2627_mock_queue = []
2728_mock_queue_done = set ()
29+ _shutdown = None
2830
2931# The maximum time (in milliseconds) that Python will try to retrieve a return value for functions executing in JS
3032# Can be overridden through `eel.init` with the kwarg `js_result_timeout` (default: 10000)
@@ -326,17 +328,24 @@ def _expose(name, function):
326328 _exposed_functions [name ] = function
327329
328330
331+ def _detect_shutdown ():
332+ if len (_websockets ) == 0 :
333+ sys .exit ()
334+
335+
329336def _websocket_close (page ):
337+ global _shutdown
338+
330339 close_callback = _start_args .get ('close_callback' )
331340
332341 if close_callback is not None :
333342 sockets = [p for _ , p in _websockets ]
334343 close_callback (page , sockets )
335344 else :
336- # Default behaviour - wait 1s, then quit if all sockets are closed
337- sleep ( 1.0 )
338- if len ( _websockets ) == 0 :
339- sys . exit ( )
345+ if _shutdown :
346+ _shutdown . kill ( )
347+
348+ _shutdown = gvt . spawn_later ( 1.0 , _detect_shutdown )
340349
341350
342351def _set_response_headers (response ):
You can’t perform that action at this time.
0 commit comments