def create_worker_pool(worker_count=None): """Create a worker pool.""" if worker_count is None: worker_count = MIN_WORKER_THREAD def job_handler(job): """Called whenever a job is available to do.""" try: func, arg = job func(arg) except Exception: # pylint: disable=broad-except # Catch any exception our service/event_listener might throw # We do not want to crash our ThreadPool _LOGGER.exception("BusHandler:Exception doing job") def busy_callback(worker_count, current_jobs, pending_jobs_count): """Callback to be called when the pool queue gets too big.""" _LOGGER.warning( "WorkerPool:All %d threads are busy and %d jobs pending", worker_count, pending_jobs_count) for start, job in current_jobs: _LOGGER.warning("WorkerPool:Current job from %s: %s", dt_util.datetime_to_local_str(start), job) return util.ThreadPool(job_handler, worker_count, busy_callback)
def create_worker_pool(thread_count=POOL_NUM_THREAD): """ Creates a worker pool to be used. """ def job_handler(job): """ Called whenever a job is available to do. """ try: func, arg = job func(arg) except Exception: # pylint: disable=broad-except # Catch any exception our service/event_listener might throw # We do not want to crash our ThreadPool _LOGGER.exception("BusHandler:Exception doing job") def busy_callback(current_jobs, pending_jobs_count): """ Callback to be called when the pool queue gets too big. """ _LOGGER.error( "WorkerPool:All %d threads are busy and %d jobs pending", thread_count, pending_jobs_count) for start, job in current_jobs: _LOGGER.error("WorkerPool:Current job from %s: %s", util.datetime_to_str(start), job) return util.ThreadPool(thread_count, job_handler, busy_callback)
def create_worker_pool(worker_count=None): """Create a worker pool.""" if worker_count is None: worker_count = MIN_WORKER_THREAD def job_handler(job): """Called whenever a job is available to do.""" try: func, *args = job func(*args) except Exception: # pylint: disable=broad-except # Catch any exception our service/event_listener might throw # We do not want to crash our ThreadPool _LOGGER.exception("BusHandler:Exception doing job") return util.ThreadPool(job_handler, worker_count)