o
    Ù­jÂ  ã                   @   sF   d Z ddlmZ ddlZe e¡Zdd„ ZG dd„ deƒZ	dd	„ Z
dS )
zFA thread pool that logs exceptions raised by tasks executed within it.é    )ÚfuturesNc                    s   ‡ fdd„}|S )z:Wraps an arbitrary callable behavior in exception-logging.c                     s.   zˆ | i |¤ŽW S  t y   t dˆ ¡ ‚ w )Nz6Unexpected exception from %s executed in logging pool!)Ú	ExceptionÚ_LOGGERÚ	exception)ÚargsÚkwargs©Úbehavior© úc/var/www/html/CropPilot/venv/lib/python3.10/site-packages/grpc/framework/foundation/logging_pool.pyÚ	_wrapping   s   þûz_wrap.<locals>._wrappingr
   )r	   r   r
   r   r   Ú_wrap   s   
r   c                   @   sB   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zddd„Z	dS )Ú_LoggingPoolzGAn exception-logging futures.ThreadPoolExecutor-compatible thread pool.c                 C   s
   || _ d S ©N)Ú_backing_pool)ÚselfÚbacking_poolr
   r
   r   Ú__init__)   s   
z_LoggingPool.__init__c                 C   s   | S r   r
   )r   r
   r
   r   Ú	__enter__,   s   z_LoggingPool.__enter__c                 C   s   | j jdd� d S )NT©Úwait©r   Úshutdown)r   Úexc_typeÚexc_valÚexc_tbr
   r
   r   Ú__exit__/   ó   z_LoggingPool.__exit__c                 O   s   | j jt|ƒg|¢R i |¤ŽS r   )r   Úsubmitr   )r   Úfnr   r   r
   r
   r   r   2   s   z_LoggingPool.submitc                 O   s$   | j jt|ƒg|¢R d| d¡iŽS )NÚtimeout)r   Úmapr   Úget)r   ÚfuncÚ	iterablesr   r
   r
   r   r!   5   s   ÿÿÿz_LoggingPool.mapTc                 C   s   | j j|d� d S )Nr   r   )r   r   r
   r
   r   r   :   r   z_LoggingPool.shutdownN)T)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r!   r   r
   r
   r
   r   r   &   s    r   c                 C   s   t t | ¡ƒS )a1  Creates a thread pool that logs exceptions raised by the tasks within it.

    Args:
      max_workers: The maximum number of worker threads to allow the pool.

    Returns:
      A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions
        raised by the tasks executed within it.
    )r   r   ÚThreadPoolExecutor)Úmax_workersr
   r
   r   Úpool>   s   
r+   )r(   Ú
concurrentr   ÚloggingÚ	getLoggerr%   r   r   Úobjectr   r+   r
   r
   r
   r   Ú<module>   s   
