diff --git a/background.py b/background.py index 05bf6e2..d6140d2 100644 --- a/background.py +++ b/background.py @@ -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