Mini Shell

Direktori : /proc/self/root/lib64/python3.6/site-packages/pyanaconda/__pycache__/
Upload File :
Current File : //proc/self/root/lib64/python3.6/site-packages/pyanaconda/__pycache__/threading.cpython-36.pyc

3

C��e9%�@sLddlZddlmZee�ZdZGdd�de�ZGdd�dej�Z	e�Z
dS)�N)�get_module_loggerZAnaWorkerThreadc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
edd��Zdd�Zdd�Zedd��Zedd��Zd d!�Zd"S)#�
ThreadManagera�A singleton class for managing threads and processes.

       Notes:
       THE INSTANCE HAS TO BE CREATED IN THE MAIN THREAD!

       This manager makes one assumption that contradicts python's
       threading module documentation.  In this class, we assume that thread
       names are unique and meaningful.  This is an okay assumption for us
       to make given that anaconda is only ever going to have a handful of
       special purpose threads.
    cCs$i|_tj�|_i|_tj�|_dS)N)�_objs�	threading�RLock�
_objs_lock�_errors�_errors_lock)�self�r�!/usr/lib64/python3.6/threading.py�__init__*s
zThreadManager.__init__cCs|S)Nr)r
rrr�__call__0szThreadManager.__call__c
CsF|j�4|j|jkr"td|j��||j|j<|j�WdQRX|jS)z�Given a Thread or Process object, add it to the list of known objects
           and start it.  It is assumed that obj.name is unique and descriptive.
        zCCannot add thread '%s', a thread with the same name already runningN)r�namer�KeyError�start)r
�objrrr�add3szThreadManager.addc	Cs"|j�|jj|�WdQRXdS)z�Removes a thread from the list of known objects.  This should only
           be called when a thread exits, or there will be no way to get a
           handle on it.
        N)rr�pop)r
rrrr�removeCszThreadManager.removec	Cs|j�||jkSQRXdS)z<Determine if a thread or process exists with the given name.N)rr)r
rrrr�existsKszThreadManager.existsc	Cs0|j� |jj|�}|r"|j|�|SQRXdS)z�Given an object name, see if it exists and return the object.
           Return None if no such object exists.  Additionally, this method
           will re-raise any uncaught exception in the thread.
        N)rr�get�raise_if_error)r
rrrrrrRs

zThreadManager.getcCs>d}y|j|�j�Wntk
r.d}YnX|j|�|S)zhWait for the thread to exit and if the thread exited with an error
           re-raise it here.
        TF)r�join�AttributeErrorr)r
rZret_valrrr�waitas

zThreadManager.waitcs��j�t�jj��}WdQRXx6|D].}�j|�tj�kr>q&tjd|��j	|�q&W�j
r��j�$dj�fdd��j
j�D��}WdQRXd|}t|��dS)zLWait for all threads to exit and if there was an error re-raise it.
        NzWaiting for thread %s to exitz, c3s|]}�j|r|VqdS)N)r)�.0�thread_name)r
rr�	<genexpr>�sz)ThreadManager.wait_all.<locals>.<genexpr>z8Unhandled errors from the following threads detected: %s)r�listr�keysrr�current_thread�log�debugr�
any_errorsr	rr�RuntimeError)r
�namesrZthread_names�msgr)r
r�wait_allys
(zThreadManager.wait_allc
Gs |j�||j|<WdQRXdS)zwSet the error data for a thread

           The exception data is expected to be the tuple from sys.exc_info()
        N)r	r)r
r�exc_inforrr�	set_error�szThreadManager.set_errorcCs|jj|�S)z7Get the error data for a thread using its name
        )rr)r
rrrr�	get_error�szThreadManager.get_errorc	Cs |j�t|jj��SQRXdS)zAReturn True of there have been any errors in any threads
        N)r	�anyr�values)r
rrrr$�szThreadManager.any_errorsc
CsN||jkrdS|j�|jj|�}WdQRX|rJ|d|d�j|d��dS)zxIf a thread has failed due to an exception, raise it into the main
           thread and remove it from errors.
        Nr��)rr	r�with_traceback)r
rr)rrrr�s
zThreadManager.raise_if_errorcCstj�tj�kS)z,Return True if it is run in the main thread.)rr!Zmain_thread)r
rrr�in_main_thread�szThreadManager.in_main_threadc	Cs|j�t|j�SQRXdS)zz Return the number of running threads.

            :returns: number of running threads
            :rtype:   int
        N)r�lenr)r
rrr�running�szThreadManager.runningc	Cs |j�t|jj��SQRXdS)z� Return the names of the running threads.

            :returns: list of thread names
            :rtype:   list of strings
        N)rrrr )r
rrrr&�szThreadManager.namesc
Cs<|j�,x$|jj�D]}|j|}|j�qWWdQRXdS)z�
        Waits for all threads that caused exceptions. In other words, waits for
        exception handling (possibly interactive) to be finished.

        N)r	rr rr)r
rZthreadrrr�wait_for_error_threads�s
z$ThreadManager.wait_for_error_threadsN)�__name__�
__module__�__qualname__�__doc__r
rrrrrrr(r*r+�propertyr$rr1r3r&r4rrrrrs"


rcsFeZdZdZe�Z�fdd�Zdd�Zdd�Zdd	�Z	d
d�Z
�ZS)�AnacondaThreada�A threading.Thread subclass that exists only for a couple purposes:

       (1) Make exceptions that happen in a thread invoke our exception handling
           code as well.  Otherwise, threads will silently die and we are doing
           a lot of complicated code in them now.

       (2) Remove themselves from the thread manager when completed.

       (3) All created threads are made daemonic, which means anaconda will quit
           when the main process is killed.
    cs�d|krd|krt|d<|jdd�}|rT|jj|d�d}||j|<|t|�|d<d|krj|jd�|_nd|_|jdd�|_|jdd�|_|jd	d�|_t	�j
||�d|_dS)
Nr�prefixrr.ZfatalTZtarget_startedZtarget_stoppedZ
target_failed)�_WORKER_THREAD_PREFIXr�_prefix_thread_countsr�str�_fatal�_target_started_callback�_target_stopped_callback�_target_failed_callback�superr
Zdaemon)r
�args�kwargsr;Z
thread_num)�	__class__rrr
�s
zAnacondaThread.__init__cCs$tjd|j|j�|jr |j�dS)NzRunning Thread: %s (%s))r"�infor�identr@)r
rrr�_target_started�szAnacondaThread._target_startedcCs$tjd|j|j�|jr |j�dS)NzThread Done: %s (%s))r"rGrrHrA)r
rrr�_target_stoppedszAnacondaThread._target_stoppedcGsRtjd|j|j�|jr,ddl}|j|�ntj|jf|��|j	rN|j	|�dS)NzThread Failed: %s (%s)r)
r"rGrrHr?�sys�
excepthook�	threadMgrr*rB)r
r)rKrrr�_target_failedszAnacondaThread._target_failedcCs\ddl}z8y|j�tjj|�Wn|j|j��YnXWdtj|j	�|j
�XdS)Nr)rKrIr�Thread�runrNr)rMrrrJ)r
rKrrrrPszAnacondaThread.run)r5r6r7r8�dictr=r
rIrJrNrP�
__classcell__rr)rFrr:�sr:)rZpyanaconda.anaconda_loggersrr5r"r<�objectrrOr:rMrrrr�<module>s5P