%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/duplicity/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/duplicity/__pycache__/asyncscheduler.cpython-312.pyc

�

�2e(��^�dZddlZddlZddlmZddlmZddlmZddlmZGd�de	�Z
y)	z_
Asynchronous job scheduler, for concurrent execution with minimalistic
dependency guarantees.
�N)�log)�async_split)�interruptably_wait)�	with_lockc�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�AsyncSchedulera�
    Easy-to-use scheduler of function calls to be executed
    concurrently. A very simple dependency mechanism exists in the
    form of barriers (see insert_barrier()).

    Each instance has a concurrency level associated with it. A
    concurrency of 0 implies that all tasks will be executed
    synchronously when scheduled. A concurrency of 1 indicates that a
    task will be executed asynchronously, but never concurrently with
    other tasks. Both 0 and 1 guarantee strict ordering among all
    tasks (i.e., they will be executed in the order scheduled).

    At concurrency levels above 1, the tasks will end up being
    executed in an order undetermined except insofar as is enforced by
    calls to insert_barrier().

    An AsynchScheduler should be created for any independent process;
    the scheduler will assume that if any background job fails (raises
    an exception), it makes further work moot.
    c�D�tj|jj�dt	d�|z���|dk\sJ|jj�d���d|_d|_||_d|_d|_	d|_
tj�|_
y)zr
        Create an asynchronous scheduler that executes jobs with the
        given level of concurrency.
        �: zinstantiating at concurrency %drz concurrency level must be >= 0FN)r�Info�	__class__�__name__�_�_AsyncScheduler__failed�_AsyncScheduler__failed_waiter�_AsyncScheduler__concurrency�_AsyncScheduler__worker_count�_AsyncScheduler__waiter_count�_AsyncScheduler__barrier�	threading�	Condition�_AsyncScheduler__cv)�self�concurrencys  �:/usr/lib/python3/dist-packages/duplicity/asyncscheduler.py�__init__zAsyncScheduler.__init__;s���
	���D�N�N�+�+�,�B�q�1R�/S�Va�/a�.b�c�d��a��\�D�N�N�$;�$;�#<�<[�!\�\����
�#���(�������������'�'�)��	�c����tj�jj�dt	d�����j
dkDr�fd�}t
�j|�yy)aL
        Proclaim that any tasks scheduled prior to the call to this
        method MUST be executed prior to any tasks scheduled after the
        call to this method.

        The intended use case is that if task B depends on A, a
        barrier must be inserted in between to guarantee that A
        happens before B.
        r
zinserting barrierrc���d�_y�NT)r�rs�r�_insert_barrierz6AsyncScheduler.insert_barrier.<locals>._insert_barrier^s
���!%��rN)r�Debugrr
rrrr)rr!s` r�insert_barrierzAsyncScheduler.insert_barrierNsX���	�	�	�T�^�^�,�,�-�R��2E�0F�/G�H�I�����!�
&�
�d�i�i��1�"rc��|�J�|jdk(rbtj|jj�dtd���tjj�|j||�Stj|jj�dtd���tjj�|j||�S)a�
        Schedule the given task (callable, typically function) for
        execution. Pass the given parameters to the function when
        calling it. Returns a callable which can optionally be used
        to wait for the task to complete, either by returning its
        return value or by propagating any exception raised by said
        task.

        This method may block or return immediately, depending on the
        configuration and state of the scheduler.

        This method may also raise an exception in order to trigger
        failures early, if the task (if run synchronously) or a previous
        task has already failed.

        NOTE: Pay particular attention to the scope in which this is
        called. In particular, since it will execute concurrently in
        the background, assuming fn is a closure, any variables used
        most be properly bound in the closure. This is the reason for
        the convenience feature of being able to give parameters to
        the call, to avoid having to wrap the call itself in a
        function in order to "fixate" variables in, for example, an
        enclosing loop.
        rr
z4running task synchronously (asynchronicity disabled)z*scheduling task for asynchronous execution)rrrrr
r�InfoCode�synchronous_upload_begin�"_AsyncScheduler__run_synchronously�asynchronous_upload_begin�#_AsyncScheduler__run_asynchronously)r�fn�paramss   r�
schedule_taskzAsyncScheduler.schedule_taskcs���2�~��~�����"�
�H�H��>�>�*�*�+�2�a�0f�.g�-h�i����5�5�
�
�+�+�B��7�7��H�H��>�>�*�*�+�2�a�0\�.]�-^�_����6�6�
�
�,�,�R��8�8rc�<���fd�}t�j|�y)aD
        Wait for the scheduler to become entirely empty (i.e., all
        tasks having run to completion).

        IMPORTANT: This is only useful with a single caller scheduling
        tasks, such that no call to schedule_task() is currently in
        progress or may happen subsequently to the call to wait().
        c�8��t�j�fd��y)Nc�D���jdk(xr�jdk(S)Nr)rrr s�r�<lambda>z4AsyncScheduler.wait.<locals>._wait.<locals>.<lambda>�s#���$�2E�2E��2J�2g�t�Ob�Ob�fg�Og�r)rrr s�r�_waitz"AsyncScheduler.wait.<locals>._wait�s����t�y�y�*g�hrN)rr)rr1s` r�waitzAsyncScheduler.wait�s���	i�	�$�)�)�U�#rc���||���fd�}tj|jj�dt	d���tj
j�|S)Nc����S�N�)�rets�r�_waiterz3AsyncScheduler.__run_synchronously.<locals>._waiter�s����Jrr
ztask completed successfully)rrrr
rr%�synchronous_upload_done)rr*r+r8r7s    @r�__run_synchronouslyz"AsyncScheduler.__run_synchronously�sU����&�k��	�	����~�~�&�&�'�r�!�,I�*J�)K�L��L�L�0�0�	
�
�rc������t��fd��\}}�fd����fd�}t�j|��j|�|S)Nc������Sr5r6)r*r+s��rr0z5AsyncScheduler.__run_asynchronously.<locals>.<lambda>�s���r�6�{�rc����jrwtj�jj�d�tj
j��j�t�jj�d���y)NzQ: _('a previously scheduled task has failed; propagating the result immediately')z7: waiter should have raised an exception; this is a bug)	rrrrr
r%�asynchronous_upload_doner�AssertionErrorr s�r�check_pending_failurezBAsyncScheduler.__run_asynchronously.<locals>.check_pending_failure�su����}�}�����~�~�.�.�/�0f�g��L�L�9�9��
�$�$�&�$��~�~�.�.�/�/j�k���rc�~�����j�jk\s�jr��jdk(r5�jsJd��d�_�jj	�nD�xj
dz
c_�jj
��xj
dzc_���j�jk\r���jr���xjdz
c_tj�jj�dtd��jfz���y)Nrzbarrier should be in effectF�r
�active workers = %d)rrrr�
notify_allrr2rr"rr
r)r@rs��r�wait_for_and_register_launchzIAsyncScheduler.__run_asynchronously.<locals>.wait_for_and_register_launch�s����!�#��%�%��);�);�;�t�~�~��&�&�!�+��>�>�H�+H�H�>�%*�D�N��I�I�(�(�*��'�'�1�,�'��I�I�N�N�$��'�'�1�,�'�%�'��%�%��);�);�;�t�~�~�
���1�$���I�I����0�0�1��A�6K�4L�PT�Pc�Pc�Oe�4e�3f�g�hr)rrr�_AsyncScheduler__start_worker)rr*r+�waiter�callerrEr@s```   @r�__run_asynchronouslyz#AsyncScheduler.__run_asynchronously�sB���&�':�;����
	�	i�&	�$�)�)�9�:����F�#��
rc�@�����fd�}tj|d�y)z%
        Start a new worker.
        c���	�j���fd�}t�j|�y#�fd�}t�j|�wxYw)Nc�����xjdzc_tj�jj�dtd��jfz����jj�y)NrBr
rC)rrr"rr
rrrDr s�r�complete_workerzJAsyncScheduler.__start_worker.<locals>.trampoline.<locals>.complete_worker�s\����'�'�1�,�'��I�I����!8�!8� 9��A�>S�<T�X\�Xk�Xk�Wm�<m�;n�o�p��I�I�(�(�*r)�_AsyncScheduler__execute_callerrr)rMrHrs ��r�
trampolinez1AsyncScheduler.__start_worker.<locals>.trampoline�sB���	
6��%�%�f�-�+�
�$�)�)�_�5��+�
�$�)�)�_�5�s	�0�A
r6N)�_thread�start_new_thread)rrHrOs`` r�__start_workerzAsyncScheduler.__start_worker�s���

	6�	� � ��R�0rc����|�\}�|s��fd�}t�j|�tj�jj
�dt
d�|z��tjj�y)Nc�p���js)d�_��_�jj�yyr)rrrrD)rrGs��r�_signal_failedz7AsyncScheduler.__execute_caller.<locals>._signal_failed�s.����}�}�$(�D�M�+1�D�(��I�I�(�(�*�%rr
z!task execution done (success: %s))	rrrrrr
rr%r>)rrH�	succeededrUrGs`   @r�__execute_callerzAsyncScheduler.__execute_caller�sf���#�H��	�6��
+�
�d�i�i��0�������'�'��5�6��B�
�

�L�L�1�1�
	
rN)r
�
__module__�__qualname__�__doc__rr#r,r2r'r)rFrNr6rrrr%s1���**�&2�*29�h
$�
�&�P1�&
rr)rZrPr�	duplicityr�duplicity.dup_threadingrrr�objectrr6rr�<module>r^s,��.�
���/�6�-�a
�V�a
r

Zerion Mini Shell 1.0