(self, max_workers=None, thread_name_prefix='',
                 initializer=None, initargs=())
Initializes a new ThreadPoolExecutor instance.

        Args:
            max_workers: The maximum number of threads that can be used to
                execute the given calls.
            thread_name_prefix: An optional name prefix to give our threads.
            initializer: A callable used to initialize worker threads.
            initargs: A tuple of arguments to pass to the initializer.
Initializes a new ThreadPoolExecutor instance.
Initializes a new ThreadPoolExecutor instance .
def __init__(self, max_workers=None, thread_name_prefix='',
                 initializer=None, initargs=()):
        """Initializes a new ThreadPoolExecutor instance.

        Args:
            max_workers: The maximum number of threads that can be used to
                execute the given calls.
            thread_name_prefix: An optional name prefix to give our threads.
            initializer: A callable used to initialize worker threads.
            initargs: A tuple of arguments to pass to the initializer.
        """
        if max_workers is None:
            # ThreadPoolExecutor is often used to:
            # * CPU bound task which releases GIL
            # * I/O bound task (which releases GIL, of course)
            #
            # We use cpu_count + 4 for both types of tasks.
            # But we limit it to 32 to avoid consuming surprisingly large resource
            # on many core machine.
            max_workers = min(32, (os.cpu_count() or 1) + 4)
        if max_workers <= 0:
            raise ValueError("max_workers must be greater than 0")

        if initializer is not None and not callable(initializer):
            raise TypeError("initializer must be a callable")

        self._max_workers = max_workers
        self._work_queue = queue.SimpleQueue()
        self._idle_semaphore = threading.Semaphore(0)
        self._threads = set()
        self._broken = False
        self._shutdown = False
        self._shutdown_lock = threading.Lock()
        self._thread_name_prefix = (thread_name_prefix or
                                    ("ThreadPoolExecutor-%d" % self._counter()))
        self._initializer = initializer
        self._initargs = initargs
def __init__ ( self , max_workers = None , thread_name_prefix = '' , initializer = None , initargs = ( ) ) : if max_workers is None : # ThreadPoolExecutor is often used to: # * CPU bound task which releases GIL # * I/O bound task (which releases GIL, of course) # # We use cpu_count + 4 for both types of tasks. # But we limit it to 32 to avoid consuming surprisingly large resource # on many core machine. max_workers = min ( 32 , ( os . cpu_count ( ) or 1 ) + 4 ) if max_workers <= 0 : raise ValueError ( "max_workers must be greater than 0" ) if initializer is not None and not callable ( initializer ) : raise TypeError ( "initializer must be a callable" ) self . _max_workers = max_workers self . _work_queue = queue . SimpleQueue ( ) self . _idle_semaphore = threading . Semaphore ( 0 ) self . _threads = set ( ) self . _broken = False self . _shutdown = False self . _shutdown_lock = threading . Lock ( ) self . _thread_name_prefix = ( thread_name_prefix or ( "ThreadPoolExecutor-%d" % self . _counter ( ) ) ) self . _initializer = initializer self . _initargs = initargs