fj l d dl Z d dlZd dlmZmZ d dlmZ e j e Z G d d Z
dS ) N)ThreadPoolExecutorFuture)BoundedSemaphorec > e Zd ZdZd Zd Zd Zd ZddZde fd Z
d
S )BoundedThreadExecutora9
BoundedExecutor behaves as a ThreadPoolExecutor which will block on
calls to submit() once the limit given as "bound" work items are queued for
execution.
While processing incoming connections, we need two things:
- the server must be able to process incoming connections
in multiple threads (one for each client) because we spend some time
trying to redirect incoming data to our servers
- the server must have some limit in order not to create new
threads indefinitely
This executor has two limits:
:param max_workers - which limits number of simultaneously running threads
:param maxqueuesize - which limits number of tasks to wait for the available thread
When both max_workers and maxqueuesize overflow, .submit function raises
queue.Full exception.
c ^ t | | _ t ||z | _ d S )N)max_workers)r executorr semaphore)selfmaxqueuesizer s J/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/agent/executor.py__init__zBoundedThreadExecutor.__init__# s, *{CCC
),*DEE c | S N )r s r __enter__zBoundedThreadExecutor.__enter__' s r c . | d S r )shutdown)r exc_typeexc_valexc_tbs r __exit__zBoundedThreadExecutor.__exit__* s
r c | j d }|st j | j j |g|R i |}| | j |S # | j xY w)NF)blocking) r acquirequeueFullr
submitadd_done_callback_on_future_completerelease)r fnargskwargssuccessfutures r r zBoundedThreadExecutor.submit- s .((%(88 * )T])">t>>>v>>F
$$T%=>>>M N""$$$s A A9Tc : | j | d S r )r
r )r waits r r zBoundedThreadExecutor.shutdown; s
t$$$$$r xc | j | rt d d S d S )NzFuture completed with exception)r r# exceptionlogger)r r+ s r r" z)BoundedThreadExecutor._on_future_complete> sN ;;== @>????? @ @r N)T)__name__
__module____qualname____doc__r r r r r r r" r r r r r s &F F F % % % %@V @ @ @ @ @ @r r )loggingr concurrent.futuresr r threadingr getLoggerr/ r. r r r r