Beispiel #1
0
    def __init__(self, max_workers=None, check_and_reject=None):
        """Initializes a thread pool executor.

        :param max_workers: maximum number of workers that can be
                            simulatenously active at the same time, further
                            submitted work will be queued up when this limit
                            is reached.
        :type max_workers: int
        :param check_and_reject: a callback function that will be provided
                                 two position arguments, the first argument
                                 will be this executor instance, and the second
                                 will be the number of currently queued work
                                 items in this executors backlog; the callback
                                 should raise a :py:class:`.RejectedSubmission`
                                 exception if it wants to have this submission
                                 rejected.
        :type check_and_reject: callback
        """
        if max_workers is None:
            max_workers = _utils.get_optimal_thread_count()
        super(ThreadPoolExecutor, self).__init__(max_workers=max_workers)
        if self._max_workers <= 0:
            raise ValueError("Max workers must be greater than zero")
        # NOTE(harlowja): this replaces the parent classes non-reentrant lock
        # with a reentrant lock so that we can correctly call into the check
        # and reject lock, and that it will block correctly if another
        # submit call is done during that...
        self._shutdown_lock = threading.RLock()
        self._check_and_reject = check_and_reject or (lambda e, waiting: None)
        self._gatherer = _Gatherer(
            # Since our submit will use this gatherer we have to reference
            # the parent submit, bound to this instance (which is what we
            # really want to use anyway).
            super(ThreadPoolExecutor, self).submit,
            self.threading.lock_object)
Beispiel #2
0
    def __init__(self, max_workers=None, check_and_reject=None):
        """Initializes a thread pool executor.

        :param max_workers: maximum number of workers that can be
                            simultaneously active at the same time, further
                            submitted work will be queued up when this limit
                            is reached.
        :type max_workers: int
        :param check_and_reject: a callback function that will be provided
                                 two position arguments, the first argument
                                 will be this executor instance, and the second
                                 will be the number of currently queued work
                                 items in this executors backlog; the callback
                                 should raise a :py:class:`.RejectedSubmission`
                                 exception if it wants to have this submission
                                 rejected.
        :type check_and_reject: callback
        """
        if max_workers is None:
            max_workers = _utils.get_optimal_thread_count()
        if max_workers <= 0:
            raise ValueError("Max workers must be greater than zero")
        self._max_workers = max_workers
        self._work_queue = compat_queue.Queue()
        self._shutdown_lock = threading.RLock()
        self._shutdown = False
        self._workers = []
        self._check_and_reject = check_and_reject or (lambda e, waiting: None)
        self._gatherer = _Gatherer(self._submit, self.threading.lock_object)
Beispiel #3
0
    def __init__(self, max_workers=None, check_and_reject=None):
        """Initializes a thread pool executor.

        :param max_workers: maximum number of workers that can be
                            simulatenously active at the same time, further
                            submitted work will be queued up when this limit
                            is reached.
        :type max_workers: int
        :param check_and_reject: a callback function that will be provided
                                 two position arguments, the first argument
                                 will be this executor instance, and the second
                                 will be the number of currently queued work
                                 items in this executors backlog; the callback
                                 should raise a :py:class:`.RejectedSubmission`
                                 exception if it wants to have this submission
                                 rejected.
        :type check_and_reject: callback
        """
        if max_workers is None:
            max_workers = _utils.get_optimal_thread_count()
        super(ThreadPoolExecutor, self).__init__(max_workers=max_workers)
        if self._max_workers <= 0:
            raise ValueError("Max workers must be greater than zero")
        # NOTE(harlowja): this replaces the parent classes non-reentrant lock
        # with a reentrant lock so that we can correctly call into the check
        # and reject lock, and that it will block correctly if another
        # submit call is done during that...
        self._shutdown_lock = threading.RLock()
        self._check_and_reject = check_and_reject or (lambda e, waiting: None)
        self._gatherer = _Gatherer(
            # Since our submit will use this gatherer we have to reference
            # the parent submit, bound to this instance (which is what we
            # really want to use anyway).
            super(ThreadPoolExecutor, self).submit,
            self.threading.lock_object)
Beispiel #4
0
 def __init__(self, max_workers=None):
     if max_workers is None:
         max_workers = _utils.get_optimal_thread_count()
     super(ProcessPoolExecutor, self).__init__(max_workers=max_workers)
     if self._max_workers <= 0:
         raise ValueError("Max workers must be greater than zero")
     self._gatherer = _Gatherer(
         # Since our submit will use this gatherer we have to reference
         # the parent submit, bound to this instance (which is what we
         # really want to use anyway).
         super(ProcessPoolExecutor, self).submit,
         self.threading.lock_object)
Beispiel #5
0
 def __init__(self, max_workers=None):
     if max_workers is None:
         max_workers = _utils.get_optimal_thread_count()
     super(ProcessPoolExecutor, self).__init__(max_workers=max_workers)
     if self._max_workers <= 0:
         raise ValueError("Max workers must be greater than zero")
     self._gatherer = _Gatherer(
         # Since our submit will use this gatherer we have to reference
         # the parent submit, bound to this instance (which is what we
         # really want to use anyway).
         super(ProcessPoolExecutor, self).submit,
         self.threading.lock_object)