current position:Home>Python ThreadPoolExecutor restrictions_ work_ Queue size

Python ThreadPoolExecutor restrictions_ work_ Queue size

2021-08-23 06:19:09 lidashuang

Use python Of futures.ThreadPoolExecutor yes , If the submit Submit tasks
ThreadPoolExecutor Will be implemented to



self._work_queue = queue.SimpleQueue()

SimpleQueue It does not limit the size of the queue , If too many tasks are submitted , Not dealt with in time , It will occupy too much memory

Can be replaced by _work_queue The implementation of the , Use queue.Queue(maxsize=maxsize)

class ThreadPoolExecutorWithQueueSizeLimit(futures.ThreadPoolExecutor):
    def __init__(self, maxsize=50, *args, **kwargs):
        super(ThreadPoolExecutorWithQueueSizeLimit, self).__init__(*args, **kwargs)
        self._work_queue = queue.Queue(maxsize=maxsize)


copyright notice
author[lidashuang],Please bring the original link to reprint, thank you.

Random recommended