/usr/lib/python3/dist-packages/twisted/python/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/python/__pycache__/threadpool.cpython-310.pyc (10502B)
o
b' @ sx d Z ddlmZmZ ddlmZ ddlmZ ddl m
Z
mZ ddlm
Z
ddlmZ ddlmZ e ZG d d
d
ZdS )z
twisted.python.threadpool: a pool of threads to which we dispatch tasks.
In most cases you can just use C{reactor.callInThread} and friends
instead of creating a thread pool directly.
)Threadcurrent_thread)List)pool)contextlog)
deprecated)Failure)Versionc @ s e Zd ZdZdZdZdZdZdZe Z
eee
dddd d
deZeeZd,dd
Zedd Zedd Zedd Zedd ZeZdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Z d-d(d)Z!d*d+ Z"dS ).
ThreadPoola
This class (hopefully) generalizes the functionality of a pool of threads
to which work can be dispatched.
L{callInThread} and L{stop} should only be called from a single thread.
@ivar started: Whether or not the thread pool is currently running.
@type started: L{bool}
@ivar threads: List of workers currently running in this thread pool.
@type threads: L{list}
@ivar _pool: A hook for testing.
@type _pool: callable compatible with L{_pool}
FNTwisted r zthreading.current_thread)versionreplacementc sb |dksJ d||ksJ d| _ | _| _g _ fdd} fdd} || _dS ) ac
Create a new threadpool.
@param minthreads: minimum number of threads in the pool
@type minthreads: L{int}
@param maxthreads: maximum number of threads in the pool
@type maxthreads: L{int}
@param name: The name to give this threadpool; visible in log messages.
@type name: native L{str}
r minimum is negativeminimum is greater than maximumc s( j | d i|} j| |S )Nname)
threadFactory
_generateNamethreadsappend)akwthreadself ;/usr/lib/python3/dist-packages/twisted/python/threadpool.pytrackingThreadFactoryL s z2ThreadPool.__init__.
.trackingThreadFactoryc s j sdS jS )Nr )startedmaxr r r r currentLimitS s z)ThreadPool.__init__..currentLimitN)minr# r r _pool_team)r
minthreads
maxthreadsr r! r$ r r r __init__8 s
zThreadPool.__init__c C s | j }|j|j S )a
For legacy compatibility purposes, return a total number of workers.
@return: the current number of workers, both idle and busy (but not
those that have been quit by L{ThreadPool.adjustPoolsize})
@rtype: L{int}
)r'
statisticsidleWorkerCountbusyWorkerCount)r statsr r r workersZ s
zThreadPool.workersc C dg| j j S )z
For legacy compatibility purposes, return the number of busy workers as
expressed by a list the length of that number.
@return: the number of workers currently processing a work item.
@rtype: L{list} of L{None}
N)r' r+ r- r r r r workingf s zThreadPool.workingc C r0 )a,
For legacy compatibility purposes, return the number of idle workers as
expressed by a list the length of that number.
@return: the number of workers currently alive (with an allocated
thread) but waiting for new work.
@rtype: L{list} of L{None}
N)r' r+ r, r r r r waitersq s
zThreadPool.waitersc s G fddd}| S )z
For legacy compatibility purposes, return an object with a C{qsize}
method that indicates the amount of work not yet allocated to a worker.
@return: an object with a C{qsize} method.
c s e Zd Z fddZdS )z$ThreadPool._queue..NotAQueuec s j jS )a
Pretend to be a Python threading Queue and return the
number of as-yet-unconsumed tasks.
@return: the amount of backlogged work not yet dispatched to a
worker.
@rtype: L{int}
)r' r+ backloggedWorkCount)qr r r qsize s z*ThreadPool._queue..NotAQueue.qsizeN)__name__
__module____qualname__r5 r r r r NotAQueue s r9 r )r r9 r r r _queue} s zThreadPool._queuec C s8 d| _ d| _| | j j}|r| j| dS dS )z'
Start the threadpool.
FTN)joinedr" adjustPoolsizer' r+ r3 grow)r backlogr r r start s zThreadPool.startc C | j d dS )z
Increase the number of available workers for the thread pool by 1, up
to the maximum allowed by L{ThreadPool.max}.
r N)r' r= r r r r startAWorker zThreadPool.startAWorkerc C s d| j pt| d| j S )z
Generate a name for a new pool thread.
@return: A distinctive name for the thread.
@rtype: native L{str}
zPoolThread--)r idr/ r r r r r s zThreadPool._generateNamec C r@ )zn
Decrease the number of available workers by 1, by quitting one as soon
as it's idle.
r N)r' shrinkr r r r stopAWorker rB zThreadPool.stopAWorkerc C s" t | d| t| | j| j d S )N__dict__)setattrr r* r% r# r stater r r __setstate__ s zThreadPool.__setstate__c C s i }| j |d<