o
    :ګec                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZ e  Zdde	de
defdd	Zde	d
e jfddZde	d
e jdee
 fddZde	fddZdde	de
defddZdedefddZde	d
e jdee
 fddZdefddZdd ZdS )    N)time)
MethodType)CallableOptionalqueuestimeoutreturnc                 C   sJ   t t  }t| | zt| || W t|  nt|  w tdd | S )a/  Waits for one or more *Queue* to be ready or until *timeout* expires.

    *queues* is a list containing one or more *Queue.Queue* objects.
    If *timeout* is not None the function will block
    for the specified amount of seconds.

    The function returns a list containing the ready *Queues*.

    c                 S   
   |    S Nemptyq r   g/vol/project/2023/60021/g236002117/DeepSeek-Coder/venv/lib/python3.10/site-packages/pebble/functions.py<lambda>,      
 zwaitforqueues.<locals>.<lambda>)	threading	ConditionLockprepare_queueswait_queuesreset_queuesfilter)r   r   lockr   r   r   waitforqueues   s   

r   r   c              	   C   sN   | D ]"}||_ |j |j|_tt||_W d   n1 sw   Y  qdS )zFReplaces queue._put() method in order to notify the waiting Condition.N)_pebble_lockmutex_put_pebble_old_methodr   
new_method)r   r   queuer   r   r   r   /   s   r   c                 C   sV   | t tdd | s|| W d    d S W d    d S 1 s$w   Y  d S )Nc                 S   r	   r
   r   r   r   r   r   r   <   r   zwait_queues.<locals>.<lambda>)anymapwait)r   r   r   r   r   r   r   8   s   "r   c              	   C   sP   | D ]#}|j  |j|_W d   n1 sw   Y  t|d t|d qdS )z$Resets original queue._put() method.Nr   r   )r   r   r   delattr)r   r!   r   r   r   r   @   s   

r   threadsc                    sZ   dt t    fdd}t|zt|  | W t nt w tdd | S )a  Waits for one or more *Thread* to exit or until *timeout* expires.

    .. note::

       Expired *Threads* are not joined by *waitforthreads*.

    *threads* is a list containing one or more *threading.Thread* objects.
    If *timeout* is not None the function will block
    for the specified amount of seconds.

    The function returns a list containing the ready *Threads*.

    Nc                     s:   |         W d    d S 1 sw   Y  d S r
   )
notify_all)argsr   old_functionr   r   new_functionZ   s   
"z$waitforthreads.<locals>.new_functionc                 S   r	   r
   is_alivetr   r   r   r   e   r   z waitforthreads.<locals>.<lambda>)r   r   r   prepare_threadswait_threadsreset_threadsr   )r&   r   r+   r   r)   r   waitforthreadsI   s   r3   r+   c                 C   s8   t  tj}| t_|W  d   S 1 sw   Y  dS )zVReplaces threading._get_ident() function in order to notify
    the waiting Condition.N_waitforthreads_lockr   	get_ident)r+   r*   r   r   r   r0   h   s
   $r0   c                 C   s   t  }|I ttdd | sF|d u r|  n|t  |  dkr,||t  |   n		 W d    d S ttdd | rW d    d S W d    d S 1 sQw   Y  d S )Nc                 S   r	   r
   r,   r.   r   r   r   r   x   r   zwait_threads.<locals>.<lambda>r   )r   r"   r#   r$   )r&   r   r   	timestampr   r   r   r1   r   s   
"r1   r*   c                 C   s0   t  | t_W d   dS 1 sw   Y  dS )z/Resets original threading.get_ident() function.Nr4   )r*   r   r   r   r2      s   "r2   c                 G   s@   | j |  | j | j  W d    d S 1 sw   Y  d S r
   )r   r   r'   )selfr(   r   r   r   r       s   
"r    r
   )r   r   typesr   typingr   r   r   r5   listfloatr   r   r   r   r   r   r3   r0   r1   r2   r    r   r   r   r   <module>   s,   	
	

