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

Requests lib block eel? #404

Closed t-walker-wei closed 3 years ago

t-walker-wei commented 3 years ago

Eel version v0.14.0

Describe the bug When a background thread running with Requests,For example : download some files with Requests. The web page cannot load eel.js, this js file http status always be pending. So everything seems blocked, cannot call python function from js,get blank screen until finish down. Have somebody face the same situation?

Code

import eel
import requests

eel.init('web')

def download_with_requests():
    url = '{some resource url}'
    temp_path = '{save path}'
    req = requests.get( url, stream=True )
    print( 'Start to download' )
    with open( temp_path, 'wb' ) as video_file:
        for chunk in req.iter_content(chunk_size=2048):
            if chunk:
                video_file.write(chunk)

# close callback for reload page exit the script issue
def on_websocket_close( page, websockets ):
    print( page, websockets )

eel.spawn( download_with_requests )

eel.start('setup.html', mode='chrome', cmdline_args=[ '--start-fullscreen'], close_callback=on_websocket_close)
kmans commented 3 years ago

Would adding block=False to eel.start() help in this case? Eel blocks by default.

t-walker-wei commented 3 years ago

Would adding block=False to eel.start() help in this case? Eel blocks by default.

I have tried to set block to False, not help. From requets-blocking-or-non-blocking, I tried grequests and httpx. Should solved issue.