Fix memory leak when using sleep in threads
This commit is contained in:
parent
b21895fa78
commit
dfd55c3957
1 changed files with 13 additions and 0 deletions
|
@ -154,6 +154,19 @@ class MainLoopCaller():
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
raise res
|
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 = MainLoopCaller()
|
||||||
main_loop.start()
|
main_loop.start()
|
||||||
patchSleep()
|
patchSleep()
|
||||||
|
|
Loading…
Reference in a new issue