
’0ýVó  ã               @   s;   d  Z  d d l Z d d l Z Gd d „  d e j ƒ Z d S)zIEnhanced Thread with support for return values and exception propagation.é    Nc               @   sa   e  Z d  Z d Z d d d f  i  d d „ Z d d „  Z d d „  Z d	 d
 „  Z d d „  Z d S)ÚREThreadz4Thread with return values and exception propagation.Nc             C   sP   t  j j |  | | | | | ƒ | |  _ | |  _ | |  _ d |  _ d |  _ d S)z<Initialize Thread, identical to threading.Thread.__init__().N)Ú	threadingÚThreadÚ__init__Ú_REThread__targetÚ_REThread__argsÚ_REThread__kwargsÚ_retvalÚ
_exception)ÚselfÚgroupÚtargetÚnameÚargsÚkwargs© r   ú1/usr/lib/python3/dist-packages/apport/REThread.pyr      s    				zREThread.__init__c          	   C   sL   |  j  rH y |  j  |  j |  j Ž  |  _ Wn t rC t j ƒ  |  _ Yn Xd S)z9Run target function, identical to threading.Thread.run().N)r   r   r   r	   ÚsysÚexc_infor
   )r   r   r   r   Úrun   s    	zREThread.runc             C   s*   |  j  ƒ  s t ‚ |  j s# t ‚ |  j S)zºReturn value from target function.

        This can only be called after the thread has finished, i. e. when
        isAlive() is False and did not terminate with an exception.
        )ZisAliveÚAssertionErrorr
   r	   )r   r   r   r   Úreturn_value&   s    zREThread.return_valuec             C   s   |  j  S)zAReturn (type, value, traceback) of the exception caught in run().)r
   )r   r   r   r   r   0   s    zREThread.exc_infoc             C   sF   |  j  rB t j d k r8 |  j  d j |  j  d ƒ ‚ n
 t d ƒ d S)zbRaise the exception caught in the thread.

        Do nothing if no exception was caught.
        Ú3é   é   z@raise self._exception[0], self._exception[1], self._exception[2]N)r
   r   ÚversionÚwith_tracebackÚexec)r   r   r   r   Ú	exc_raise5   s    	 zREThread.exc_raise)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r      s   


r   )r"   r   r   r   r   r   r   r   r   Ú<module>   s   