14 """A thread pool that logs exceptions raised by tasks executed within it."""
16 from concurrent
import futures
19 _LOGGER = logging.getLogger(__name__)
23 """Wraps an arbitrary callable behavior in exception-logging."""
25 def _wrapping(*args, **kwargs):
27 return behavior(*args, **kwargs)
30 'Unexpected exception from %s executed in logging pool!',
38 """An exception-logging futures.ThreadPoolExecutor-compatible thread pool."""
49 def submit(self, fn, *args, **kwargs):
52 def map(self, func, *iterables, **kwargs):
55 timeout=kwargs.get(
'timeout',
None))
62 """Creates a thread pool that logs exceptions raised by the tasks within it.
65 max_workers: The maximum number of worker threads to allow the pool.
68 A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions
69 raised by the tasks executed within it.
71 return _LoggingPool(futures.ThreadPoolExecutor(max_workers))