Fix memory leak when using sleep in threads

This commit is contained in:
shortcutme 2019-12-17 14:50:38 +01:00
parent b21895fa78
commit dfd55c3957
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -154,6 +154,19 @@ class MainLoopCaller():
return res
else:
raise res
def patchSleep(): # Fix memory leak by using real sleep in threads
real_sleep = gevent.monkey.get_original("time", "sleep")
def patched_sleep(seconds):
if isMainThread():
gevent.sleep(seconds)
else:
real_sleep(seconds)
time.sleep = patched_sleep
main_loop = MainLoopCaller()
main_loop.start()
patchSleep()