Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing memory leak that leaves values and callbacks in memory indefinitely #542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion eel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
_eel_js = open(_eel_js_file, encoding='utf-8').read()
_websockets = []
_call_return_values = {}
_call_return_msgs = {}
_call_return_callbacks = {}
_call_number = 0
_exposed_functions = {}
Expand Down Expand Up @@ -305,6 +306,7 @@ def _process_message(message, ws):
elif message['status'] == 'error' and error_callback is not None:
error_callback(message['error'], message['stack'])
else:
_call_return_msgs[call_id] = message
_call_return_values[call_id] = message['value']

else:
Expand Down Expand Up @@ -353,12 +355,23 @@ def _call_return(call):

def return_func(callback=None, error_callback=None):
if callback is not None:
_call_return_callbacks[call_id] = (callback, error_callback)
if call_id in _call_return_msgs:
_call_return_values.pop(call_id)
message = _call_return_msgs.pop(call_id)
if message['status'] == 'ok':
callback(message['value'])
elif message['status'] == 'error' and error_callback is not None:
error_callback(message['error'], message['stack'])
else:
_call_return_callbacks[call_id] = (callback, error_callback)

else:
for w in range(_js_result_timeout):
if call_id in _call_return_values:
_call_return_msgs.pop(call_id, None)
return _call_return_values.pop(call_id)
sleep(0.001)

return return_func


Expand Down