Open nh916 opened 2 years ago
Stopping the Eel Server when clients disconnect isn't always wanted behaviour. You can implement the functionality yourself though by calling a python function that stops the server when the website unloads(closes). On JS side it would be:
window.addEventListener("beforeunload", () => { eel.close_python()} );
And in Python:
import sys
@eel.expose
def close_python(*args):
sys.exit()
Hey @nh916, thanks for the question!
I'll start by saying there are a lot of nuances when working with threads... without seeing an exact code example it's hard for me to make recommendations. That said, if you start up additional non-daemon threads and those are still running when the browser is closed, then yeah you're right, the Python application will continue running until those threads are finished.
As @Blauschirm mentioned, halting those threads isn't always wanted because they might be doing a critical bit of work such as saving a file, updating a database, or similar. Therefore, Eel doesn't try to brute force stop them.
You have at least three options here:
daemon=True
on them and they'll be closed when the main thread is stopped (when the browser is closed)close_callback
that can be passed to eel.start
and do whatever you want to shut down those additional threads (including a brute force exit if you choose)Regarding recommendation 2 from above... I wouldn't necessarily recommend this, but this is what I mean:
def close(page, sockets_still_open):
os._exit(0)
eel.start('index.html', close_callback=close)
Hope this helps!
Can anyone share a Demo for this behavior, I cannot get this to work.
This can be referenced at - https://github.com/python-eel/Eel/issues/259
Firstly remember to link the eel.js on HTML files can work.
I am faced with this issue as well. Finally found this is the error from eel__init.py. If import sys
or from sys import exit
is missing in your .py files, this will happen.
But I tried from sys import exit
it still didn't work. I eventually changed eel\init__.py from line 373:
if len(_websockets) == 0:
exit()
to
if len(_websockets) == 0:
sys.exit()
and adding to your .py files:
import sys
then works.
Eel version 0.14.0
Describe the bug: When the user is running the app, decides to close the app window GUI, the user believes they have ended the program but the python program is still running in the background and the user has no idea
To Reproduce: Steps to reproduce the behavior:
Expected behavior: I expect both the app GUI and the python program to close when I closed the window
Desktop: