python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.44k stars 587 forks source link

close_callback parameter is never being called #357

Closed LQR471814 closed 4 years ago

LQR471814 commented 4 years ago

Problem

eel.start() keyword parameter close_callback is never called on window close, it is also never called when killing the process.

Code

import eel

eel.init('web')

@eel.expose
def handle_exit(ar1, ar2):
    import sys
    print("exit")
    sys.exit(0)

if __name__ == "__main__":
    eel.start("index.html", size=(1280, 768), port=3000, host="localhost", close_callback=handle_exit)

index.html

<!DOCTYPE HTML>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Test</title>
</head>

<body>
  <h1>Test</h1>
</body>
</html>

Folder Structure

.
+-- web
|    +-- index.html
+-- app.py

What I've tried

I tried setting all the parameters with options={...} however it was the same result I tried removing @eel.expose however it was the same result I tried making eel.start non-blocking then putting a while True: eel.sleep(10) after however it was the same result I tried default parameters except for close_callback however it was the same result I tried both python versions 3.7.8 and 3.8.1 I tried using a different browser (edge) however it was the same result I tried building with PyInstaller but it had the same behaivior. I tried on a Macbook Air Running OSX ver 10.15.5 and Python 3.7.4 (with py3.7-dev because I needed to install eel) and the same code.

Output upon ctrl+c the blocking code

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\gevent\_ffi\loop.py", line 269, in python_check_callback
    def python_check_callback(self, watcher_ptr): # pylint:disable=unused-argument
KeyboardInterrupt
2020-07-18T19:19:09Z

Information

OS: Windows 10 v10.0.19041 Build 19041 and macOS Catalina ver 10.15.5 (I tried both with different python installations and setups however it had the same problem) Browser: Chrome v83.0.4103.116 and Edge v83.0.478.61 Python: Python v3.7.8, Python v3.7.4 (with dev headers) and Python v3.8.1 (I tried both) Eel: Eel v0.13.2

LQR471814 commented 4 years ago

Oops, sorry I solved it by myself. I didn't include <script type="text/javascript" src="/eel.js"></script> in my HTML file.