
    TAi                        S r SSKJr  SSKrSSKJrJr  SSKJrJ	r	  SSK
JrJr  SSKJrJr  \" S5      rS	 rSS
 jr " S S\5      rSS jr " S S\5      rg)z"OCRmyPDF concurrency abstractions.    )annotationsN)ABCabstractmethod)CallableIterable)AnyTypeVar)NullProgressBarProgressBarTc                     g N )_args_kwargss     P/var/www/html/land-ocr/venv/lib/python3.13/site-packages/ocrmypdf/_concurrent.py
_task_noopr      s    
    c                $    UR                  5         g r   )update)_resultpbars     r   _task_finished_noopr      s    KKMr   c                      \ rS rSrSr\R                  " 5       r\r	SS.S jr
SSSSS.               S	S jjr\              S
S j5       rSrg)Executor   zAbstract concurrent executor.N
pbar_classc                    U(       a  Xl         g g r   r   )selfr   s     r   __init__Executor.__init__    s    (O r   )worker_initializertasktask_argumentstask_finishedc                   U(       d  gU(       d  [         nU(       d  [        nU(       d  [         nU R                     U R                  UUUUUUUS9  SSS5        g! , (       d  f       g= f)ab  Set up parallel execution and progress reporting.

Args:
    use_threads: If ``False``, the workload is the sort that will benefit from
        running in a multiprocessing context (for example, it uses Python
        heavily, and parallelizing it with threads is not expected to be
        performant).
    max_workers: The maximum number of workers that should be run.
    progress_kwargs: Arguments to set up the progress bar.
    worker_initializer: Called when a worker is initialized, in the worker's
        execution context. If the child workers are processes, it must be
        possible to marshall/pickle the worker initializer.
        ``functools.partial`` can be used to bind parameters.
    task: Called when the worker starts a new task, in the worker's execution
        context. Must be possible to marshall to the worker.
    task_finished: Called when a worker finishes a task, in the parent's
        context.
    task_arguments: An iterable that generates a group of parameters for each
        task. This runs in the parent's context, but the parameters must be
        marshallable to the worker.
N)use_threadsmax_workersprogress_kwargsr#   r$   r%   r&   )r   r   	pool_lock_executer    r(   r)   r*   r#   r$   r%   r&   s           r   __call__Executor.__call__$   s[    @ !!+/MD^^MM'' /#5-+   ^^s   A
A)c                   g)z-Custom executors should override this method.Nr   r-   s           r   r,   Executor._executeX   s    r   )r(   boolr)   intr*   dictr#   zCallable | Noner$   zCallable[..., T] | Noner%   zIterable | Noner&   z'Callable[[T, ProgressBar], None] | NonereturnNoner(   r2   r)   r3   r*   r4   r#   r   r$   r   r%   r   r&   r   )__name__
__module____qualname____firstlineno____doc__	threadingLockr+   r
   r   r!   r.   r   r,   __static_attributes__r   r   r   r   r      s    ' I J%) ) /3(,*.AE2 2 	2
 2 ,2 &2 (2 ?2 
2h < < 	<
 < %< < !<  < <r   r   c                h    U R                   R                  5       nU R                   R                  US9$ )N)progressbar_class)hookget_progressbar_classget_executor)plugin_managerr   s     r   setup_executorrF   g   s0    $$::<J++j+IIr   c                  >    \ rS rSrSr              SS jrSrg)SerialExecutorl   zImplements a purely sequential executor using the parallel protocol.

The current process/thread will be the worker that executes all tasks
in order. As such, ``worker_initializer`` will never be called.
c                   U R                   " S0 UD6 nU H  n	U" U	6 n
U" X5        M     S S S 5        g ! , (       d  f       g = f)Nr   r   )r    r(   r)   r*   r#   r$   r%   r&   r   argsresults              r   r,   SerialExecutor._executes   s<     __//4&tf+ ' 0//s	   3
Ar   Nr7   )r8   r9   r:   r;   r<   r,   r?   r   r   r   rH   rH   l   sR    , , 	,
 , %, , !,  ,r   rH   )r   r   r   r   )r5   r   )r<   
__future__r   r=   abcr   r   collections.abcr   r   typingr   r	   ocrmypdf._progressbarr
   r   r   r   r   r   rF   rH   r   r   r   <module>rS      sP    ) "  # .  >CLJ<s J<ZJ
,X ,r   