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

Calling eel.sleep from a thread creates an anon_inode and eventually "too many files open" error #461

Closed aaknitt closed 3 years ago

aaknitt commented 3 years ago

Eel version 0.11.1

Describe the bug When eel.sleep() is called from another thread, an anon_inode is created. If this happens enough, a "too many files open" error from the OS can be produced. For example, on a Raspberry Pi the default maximum number of file descriptors that a single process can have open is 1024. So if eel.sleep() is called 1024 times from a thread, this error will occur.

To Reproduce Minimal script to produce issue (reproducible on a Raspberry Pi running standard OS):

import eel
import _thread

eel.init('gui')
eel.start('index.html',port=7711,block=False)

def newdelay():
    eel.sleep(.001)
    print("done sleeping in thread - this created an a_inode")
    return

while 1:
    eel.sleep(0.01)
    _thread.start_new_thread(newdelay,())
    f = open('test.txt','w')
    f.close()

After this script is started, check the number of file descriptors that it has open by running (it will increase quickly): lsof -p [PID of script] | wc -l

After about 11 seconds the "too many files open" error will occur.

Additional context Based on this, it seems that this could potentially be an underlying issue with gevent: https://stackoverflow.com/questions/50300407/python-ubuntu-too-many-open-files-eventpoll

Also see here: https://github.com/eventlet/eventlet/issues/197

ChrisKnott commented 3 years ago

This might be a problem with gevent. I will look into this

aaknitt commented 3 years ago

For what it's worth, I updated gevent on my Pi from 1.4.0 to 21.8.0 and it's still having the same issue.

Any suggestions for workarounds to get time.sleep() type functionality within a thread?

aaknitt commented 3 years ago

I also confirmed that this is likely an issue in gevent and opened an issue there: https://github.com/gevent/gevent/issues/1816

aaknitt commented 3 years ago

Closing based on this: https://github.com/gevent/gevent/issues/1816