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

Weird behavior in spawned thread #389

Open Alzomra opened 4 years ago

Alzomra commented 4 years ago

Eel version 0.14.0

Describe the bug my app is setup to switch the webpage depending on a button wired to Raspberry pi , but for testing purposes i emulate the buttons with True or False values , but i get weird but a bit consistent behavior , when i set 2 buttons to True the first will run ( and become false ) and then when the second screen ( button 2) is supposed to be ran , the first one is called another time.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'eelgui'
  2. Click on 'app.p'
  3. Scroll down to '....'
  4. See error

Expected behavior "product2" screen is shown when Pin2 is True , "product3" is shown when "pin3" is True Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

)

Additional context (ignore the json file) Script :

import eel
import logging
import gevent.monkey
import json

logging.basicConfig(level=logging.DEBUG , format='[%(levelname)s] (%(threadName)-10s) %(message)s')

eel.init('web')
new_stat={"product1" : 0 , "product2" : 0 , "product3" : 0}
try :
    with open("stat.json", "r") as read_file:
      data = json.load(read_file)
except FileNotFoundError : 
    with open("stat.json", "w") as read_file:
      data = json.dump(new_stat,read_file)
def my_other_thread( ):
    Pin1 = False
    Pin2 = True
    Pin3 = False
    reset = 0
    while True :
              reset += 1
              with open("stat.json", "r") as read_file:
                data = json.load(read_file)
              if Pin1:
                  eel.redirect_function("p1")
                  Pin1 = False
                  data["product1"]+=1
                  reset = 0 
                  eel.sleep(0.1)
              elif Pin2:
                  eel.redirect_function("p2")

                  data["product2"]+=1
                  reset = 0 
                  eel.sleep(5.0)
                  Pin2 = False
                  Pin3 = True
              elif Pin3 :
                  eel.redirect_function("p3")
                  Pin3 = False
                  data["product3"]+=1
                  reset = 0 
                  eel.sleep(0.1)
              elif reset >= 100 :
                  reset = 0
                  eel.redirect_function("h")
                  eel.sleep(0.1)
              with open("stat.json", "w") as read_file:
                data = json.dump(data,read_file)    
              eel.sleep(0.1)

gevent.monkey.patch_all()
eel.spawn(my_other_thread)
eel.start('home.html', mode='chrome' , block=False)

while True :
    eel.sleep(5.0)
samuelhwilliams commented 4 years ago

Hi 👋 Sorry you seem to be having a problem with Eel. Thanks for sharing your Python code. It would be useful if you could share all the code needed to reproduce this issue (i.e. the html files, directory structure, etc). It would be easiest if you can simply share the repository containing your code.

Without this all it's a bit of a guessing game on our end.

Alzomra commented 4 years ago

sorry for not including the full folder , its a bit heavy to upload on my bad connection , i attached below the full directory (not including the videos and images for hmtl) , it should go from "home" page to "product 3" after passing the 10 seconds on "product2" page and turning Pin3 to True. Eelgui.zip

Alzomra commented 4 years ago

also , i having problems with mozilla firefox , when i set it to default browser and launch the app , i need to reload the page for it to display the pages.