a
    !f                     @   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                     s6   z | i |W S  t y0   td   Y n0 d S )Nz6Unexpected exception from %s executed in logging pool!)	Exception_LOGGER	exception)argskwargsbehavior g/var/www/html/python-backend/venv/lib/python3.9/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)selfZ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__.   s    z_LoggingPool.__exit__c                 O   s   | j jt|g|R i |S r   )r   submitr   )r   fnr   r   r
   r
   r   r   1   s    z_LoggingPool.submitc                 O   s&   | j jt|g|R d|dd iS )Ntimeout)r   mapr   get)r   func	iterablesr   r
   r
   r   r   4   s
    
z_LoggingPool.mapTc                 C   s   | j j|d d S )Nr   r   )r   r   r
   r
   r   r   9   s    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 )a%  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   
