mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Fix the Check Book tool leaking threads
This commit is contained in:
parent
d758d88191
commit
b9e7dc6190
@ -8,6 +8,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing.pool import ThreadPool
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
from calibre import detect_ncpus as cpu_count
|
from calibre import detect_ncpus as cpu_count
|
||||||
|
|
||||||
@ -31,13 +32,6 @@ class BaseError(object):
|
|||||||
|
|
||||||
__repr__ = __str__
|
__repr__ = __str__
|
||||||
|
|
||||||
class Worker(object):
|
|
||||||
|
|
||||||
def __init__(self, func):
|
|
||||||
self.func = func
|
|
||||||
self.result = None
|
|
||||||
self.tb = None
|
|
||||||
|
|
||||||
def worker(func, args):
|
def worker(func, args):
|
||||||
try:
|
try:
|
||||||
result = func(*args)
|
result = func(*args)
|
||||||
@ -52,6 +46,7 @@ def run_checkers(func, args_list):
|
|||||||
num = cpu_count()
|
num = cpu_count()
|
||||||
pool = ThreadPool(num)
|
pool = ThreadPool(num)
|
||||||
ans = []
|
ans = []
|
||||||
|
with closing(pool):
|
||||||
for result, tb in pool.map(partial(worker, func), args_list):
|
for result, tb in pool.map(partial(worker, func), args_list):
|
||||||
if tb is not None:
|
if tb is not None:
|
||||||
raise Exception('Failed to run worker: \n%s' % tb)
|
raise Exception('Failed to run worker: \n%s' % tb)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user