Move file writes and reads to separate thread

This commit is contained in:
shortcutme 2019-11-19 02:16:20 +01:00
parent 5d113757df
commit 58214c0ac3
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
3 changed files with 71 additions and 3 deletions

22
src/util/ThreadPool.py Normal file
View file

@ -0,0 +1,22 @@
import gevent.threadpool
class ThreadPool:
def __init__(self, max_size):
self.setMaxSize(max_size)
def setMaxSize(self, max_size):
self.max_size = max_size
if max_size > 0:
self.pool = gevent.threadpool.ThreadPool(max_size)
else:
self.pool = None
def wrap(self, func):
if self.pool is None:
return func
def wrapper(*args, **kwargs):
return self.pool.apply(func, args, kwargs)
return wrapper