Make ThreadPool a context manager to prevent memory leaks

This commit is contained in:
Ivanq 2020-03-04 22:11:59 +03:00
parent c4f65a5d7b
commit 09e65e1d95
3 changed files with 99 additions and 99 deletions

View file

@ -55,6 +55,12 @@ class ThreadPool:
del self.pool
self.pool = None
def __enter__(self):
return self
def __exit__(self, *args):
self.kill()
lock_pool = gevent.threadpool.ThreadPool(50)
main_thread_id = threading.current_thread().ident