Update thread.py

This commit is contained in:
tianc777 2020-12-20 10:25:48 +08:00 committed by GitHub
parent 273043c42c
commit 42370c8dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -108,6 +108,11 @@ class BrokenThreadPool(_base.BrokenExecutor):
Raised when a worker thread in a ThreadPoolExecutor failed initializing.
"""
class RejectedExecutionException(Exception):
"""
Raised when the work queue is full.
"""
class ThreadPoolExecutor(_base.Executor):
@ -121,6 +126,7 @@ class ThreadPoolExecutor(_base.Executor):
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.
queue_size: The size limit for work queue.
initializer: A callable used to initialize worker threads.
initargs: A tuple of arguments to pass to the initializer.
"""
@ -165,7 +171,10 @@ class ThreadPoolExecutor(_base.Executor):
f = _base.Future()
w = _WorkItem(f, fn, args, kwargs)
try:
self._work_queue.put(w)
except queue.Full:
raise RejectedExecutionException()
self._adjust_thread_count()
return f
submit.__doc__ = _base.Executor.submit.__doc__