question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error when using block=False on eel.start()

See original GitHub issue

I was trying to use block=False on eel.start() and mode=None to start the server without any GUI anbd then, with cefpython, open a new GUI. When i tried this, CEFpython appeared with a white screen, and then I tried mode=“chrome”, and chrome displayed error saying that localhost:4567 was not accesible, but if I set block=True it was working perfectly.

Python3 64bit Windows 10 Pro 64bit Cefpython v66 chrome 83

Code:

import eel
eel.init('web')
eel.start(mode=chrome, port=4567, block=True) #Working Fine
eel.start(mode=chrome, port=4567, block=False) #Page not found Error like this:

image

<html>
   <!-- some html text-->
</html>

Thanks 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
martinet101commented, Jul 1, 2020

Well, Finally I managed to make it work. I used Process from multiprocessing instead of eel.spawn, because I needed two REAL different processes, not an emulation, because eel.spawn() uses a thread. Now it works, and the full code is that one:


@eel.expose
def checkUpdates_py():
    actualVersion = 2.4
    if True:
        import struct
        import urllib.request
        response = urllib.request.urlopen("http://www.somepythonthings.tk/versions/calc.html")
        response = response.read().decode("utf8")
        if float(response)>actualVersion:
            return True
        else:
            return False
    else:
        return False
@eel.expose
def downloadUpdates():
    import webbrowser
    webbrowser.open_new('https://www.somepythonthings.tk/programs/somepythonthings-calc/')
    
def eval2(s):
    try:
        return str(eval(str(s)))
    except:
        return 'Oh 💩, You did it again! The operation is too hard to be calculated!'
@eel.expose
def py_eval(s):
    return eval2(s)
@eel.expose()
def python_alive():
    return True

def server_process():
    print('Starting Eel')
    eel.start('index.html',mode=None, size=(900, 500), port=4567,  block=False)
    while True:
        print("Eel Server Running")
        eel.sleep(1.0)   

#This eel.init('web') crashes if it is on the "if __name__ == '__main__':"
eel.init('web')

if __name__ == '__main__':
    
    from cefpython3 import cefpython as cef
    from multiprocessing import Process
    import sys
    p = Process(target=server_process)
    p.start()
    sys.excepthook = cef.ExceptHook
    cef.Initialize()
    cef.CreateBrowserSync(url="localhost:4567/index.html")
    cef.MessageLoop()
    cef.Shutdown()


The thing is that now i can have the cef.MessageLoop() and eel.start() with its while True: working at the same time.

(If you try to run this, do NOT try it on IDLE, because it won’t work on idle, it needs to be executed as a .py file.)

Lots of thanks for the help 😄. I’ll close this, because the problem is now solved.

0reactions
martinet101commented, Jun 29, 2020

Not working… I’m trying this:


import eel
eel.init('web')

def cef_thread():
    from cefpython3 import cefpython as cef
    import sys
    eel.sleep(5)
    sys.excepthook = cef.ExceptHook
    cef.Initialize()
    cef.CreateBrowserSync(url="localhost:4567")
    cef.MessageLoop()
    cef.Shutdown()
    while True:
        print("I'm a thread")
        eel.sleep(1.0)                  

eel.spawn(cef_thread)

eel.start('index.html',mode='chrome', size=(900, 500), port=4567,  block=False)  

while True:
    print("I'm a main loop")
    eel.sleep(1.0)   

So, It starts running nice for the 5 first seconds (ot for the x seconds that are set on line 7) and then, while cefpython is running, the main loop stops printing “I’m a main loop” and if I reload the chrome window, it gives me the error. Then, when I close the cefpython window, the program starts printing “I’m a thread” as normal, because the cef_thread() function ends with a final loop, and the “I’m a main loop” loop recovers activity, and, if I reolad chrome window, it reloads perfectly the localhost:4567 page. So I think the solution may be to run the cef_thread() on another process, instead of running it with eel.spawn(). Because the server and cef are running on the same process, and cef has a cef.MessageLoop that stills running until cef is colsed. I’ll try it out and post the results…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blocking False is not working · Issue #477 · python-eel/Eel
Eel version 0.14.0 Describe the bug When I use the eel.start("index.html", blocking=False) statement then the browser opens with the ...
Read more >
Python: running eel with multithreading results in a error
Solution. Your code is starting two threads and immediately exits main thread, which causes the rest of the threads to ...
Read more >
Top 5 Eel Code Examples - Snyk
To help you get started, we've selected a few Eel examples, based on popular ways it is used in public projects. Secure your...
Read more >
Eel - PyPI
Eel is a little Python library for making simple Electron-like offline HTML/JS GUI apps, with full access to Python capabilities and libraries.
Read more >
Python GUI Using Chrome - Nitratine
start(). If you want to execute code underneath eel.start() you can pass block=False as an argument to stop it from blocking. For ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found