Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
This commit is contained in:
2017-09-02 19:36:30 -04:00
parent 50528f98b2
commit dfed1d5cfb
+5
View File
@@ -3,6 +3,7 @@
import multiprocessing
import concurrent.futures
def default_n():
return multiprocessing.cpu_count()
@@ -11,6 +12,7 @@ pool = concurrent.futures.ThreadPoolExecutor(max_workers=n)
callbacks = []
results = []
def run(f, *args, **kwargs):
pool._max_workers = n
@@ -33,8 +35,11 @@ def task(f, *args, **kwargs):
return result
return do_task
def callback(f):
callbacks.append(f)
def register_callback():
f()
return register_callback