python-eel / Eel

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

With block=False and reading from sys.stdin, localhost doens't connect #402

Open vshesh opened 3 years ago

vshesh commented 3 years ago

Eel version 0.14.0

Describe the bug Running eel in non blocking mode, then reading from sys.stdin in a loop causes a localhost failed to connect in chrome.

what happens

Screen Shot 2020-10-25 at 8 10 30 PM

To Reproduce Steps to reproduce the behavior:

  1. create some web folder with a dummy index.html file
    <!doctype html>
    <html>
    <head></head>
    <body>
    <div id="container">
        <svg id="drawing"></svg>
    </div>
    <script src="https://d3js.org/d3.v6.min.js"></script>
    <script type="text/javascript" src="/eel.js"></script>
    <script src="index.js"></script>
    </body>
    </html>
  2. put this in a python file
    
    import eel
    import sys

eel.init('web') eel.start('index.html', block=False)

while True: for l in sys.stdin: eel.draw([['x', 1, random.random()500, random.random() 500]])


3. put this in a js file

```js
eel.expose(draw)
function draw(to_draw) {
  d3.select('svg#drawing').selectAll('text')
  .data(to_draw).attr('x', d => d[2]).attr('y', d => d[3]).text(d => d[0])
  .enter().append('text').attr('x', d => d[2]).attr('y', d => d[3]).text(d => d[0])
  .exit().remove()
}

Expected behavior App should open as normal and display results of drawing a random x every second.

Desktop (please complete the following information):

Additional context Doing something non sys.stdin related in the while True loop works just fine, like

while True: 
  eel.draw([['x', 1, random.random()*500, random.random()*500]])
  eel.sleep(0.2)
RaySuhyunLee commented 2 years ago

I have the same issue. I guess when the io-related blocking happens, it prevents the server from running properly.

eatsana commented 2 years ago

I'm having the exact same problem. I'm using a simple hello world eel project. When adding block=False, eel can no longer connect. It's super frustrating.

Xyndra commented 2 years ago

Same problem here, although I don't use io things

GabrielLins64 commented 2 years ago

Some issue here.

flappix commented 1 year ago

Same here. As a workaround you can launch eel in a thread

import threading
import eel

def start_gui():
    eel.init ('gui')
    eel.start ('index.html')

gui_thread = threading.Thread (target=start_gui)
gui_thread.daemon = True
gui_thread.start()

# do other stuff