
    gi<                        d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZ dd	lmZmZ  ej        e          Z G d
 d          ZdS )a  
A minimal scheduler to schedule tasks to run in the future (sync version).

Inspired to the standard library `sched.scheduler`, but designed for
multi-thread usage from the ground up, not as an afterthought. Tasks can be
scheduled in front of the one currently running and `Scheduler.run()` can be
left running without any tasks scheduled.

Tasks are called "Task", not "Event", here, because we actually make use of
`[threading/asyncio].Event` and the two would be confusing.
    )annotationsN)	monotonic)heappopheappush)AnyCallable   )Task)EventLockc                  2    e Zd ZddZdZdd
ZddZddZdS )	SchedulerreturnNonec                `    g | _         t                      | _        t                      | _        d S )N)_queuer   _lockr   _event)selfs    b/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/psycopg_pool/sched.py__init__zScheduler.__init__!   s#    "$VV
gg    g     @delayfloatactionCallable[[], Any] | Noner
   c                P    t                      |z   }|                     ||          S )zpEnter a new task in the queue delayed in the future.

        Schedule a `!None` to stop the execution.
        )r   enterabs)r   r   r   times       r   enterzScheduler.enter(   s&    
 {{U"}}T6***r   r   c                    t          ||          }| j        5  t          | j        |           | j        d         |u }ddd           n# 1 swxY w Y   |r| j                                         |S )znEnter a new task in the queue at an absolute time.

        Schedule a `!None` to stop the execution.
        r   N)r
   r   r   r   r   set)r   r   r   taskfirsts        r   r   zScheduler.enterabs0   s    
 D&!!Z 	+ 	+T[$'''KNd*E	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+  	KOOs   %A		AAc                   | j         }	 | j        5  t                      }|r|d         ndx}r(|j        |k    rt	          |           n|j        |z
  }d}n| j        }| j                                         ddd           n# 1 swxY w Y   |rb|j        sdS 	 |                                 n]# t          $ r6}t                              d|j        |j        j        |           Y d}~n"d}~ww xY w| j                            |           )zExecute the events scheduled.Tr   Nz$scheduled task run %s failed: %s: %s)r   r   r   r   r   EMPTY_QUEUE_TIMEOUTr   clearr   	Exceptionloggerwarning	__class____name__wait)r   qnowr#   r   es         r   runzScheduler.run?   s   K	( 
$ 
$kk$%/AaDD404 5yC''



 $	C# 4E!!###
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$  ({ EKKMMMM    NN>,	          '''7	(s*   A%BBBB- -
C-7,C((C-N)r   r   )r   r   r   r   r   r
   )r   r   r   r   r   r
   )r,   
__module____qualname__r   r&   r    r   r1    r   r   r   r      sl           
  + + + +   ( ( ( ( ( (r   r   )__doc__
__future__r   loggingr   r   heapqr   r   typingr   r   _taskr
   _acompatr   r   	getLoggerr,   r)   r   r4   r   r   <module>r=      s   
 
 # " " " " "        # # # # # # # #                       ! ! ! ! ! ! ! !		8	$	$>( >( >( >( >( >( >( >( >( >(r   