mirror of
https://github.com/kennethreitz/background.git
synced 2026-06-05 23:10:18 +00:00
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user