sortfact
sortfact

Reputation: 31

How to close eel? or start code with a separate process?

I want to close the browser and to continue the code.

def run():
    @eel.expose
    def end_browser():
        print("YES2")
        eel.end()
        eel.close()
        os._exit(0) 

    eel.init('web')
    eel.start("test.html", size=(700,700))
    

run()

print("Continue")

I was advised to use the subprocess.

import subprocess

process = subprocess.run([???], capture_output=True, shell=True)
print(process.returncode) # return 2 if was error

print("Continue code")

But I did not quite understand what you need to write in brackets to start the function.
How can I close part of the code that it continued on?

Upvotes: 2

Views: 2351

Answers (1)

kaiser
kaiser

Reputation: 1009

The simplest way is to hook the close_callback:

# (python file)

def start():
  eel.init('web')
  eel.start("test.html", size=(700,700), close_callback=keep_going)

def keep_going(a,b):
  # code will be called after browser window is closed

This way you can just continue your work in python.

To close the window from Python code, I use a exposed javascript function:

// (javascript file)

eel.expose(close_window)
function close_window() {
    window.close()
}

After the window is closed, again the callback function will be triggered.

Upvotes: 0

Related Questions