@contextlib.contextmanager<EOL>def pool_boy(Pool, traces, **kwargs):
<EOL>n_cores = kwargs.get('<STR_LIT>', cpu_count())<EOL>if n_cores is None:<EOL><INDENT>n_cores = cpu_count()<EOL><DEDENT>if n_cores > traces:<EOL><INDENT>n_cores = traces<EOL><DEDENT>pool = Pool(n_cores)<EOL>yield pool<EOL>pool.close()<EOL>pool.join()<EOL>
A context manager for handling the setup and cleanup of a pool object.

:param Pool: any Class (not instance) that implements the multiprocessing
    Pool interface
:param traces: The number of traces to process
:type traces: int