-=[ Mr. Bumblebee ]=-
_Indonesia_
σ
ΉΰνNc @@ sE d d l m Z d d l Z d d l Z d e j f d YZ d S( i ( t absolute_importNt CatchingExceptionThreadc B@ s} e Z d Z d Z e j d
k rB e e j j e j j
Z n d Z d Z
d Z d Z d d Z d Z RS( s‘ A thread that keeps track of exceptions.
If an exception occurs during the thread execution, it's caught and
re-raised when the thread is joined().
c O@ s~ y | j d } Wn t k
r2 t j } n Xt t | j | | | j | d | _ d | _
t j | _ d S( Nt
sync_event(
t popt KeyErrort threadingt Eventt superR t __init__t set_sync_eventt Nonet exceptiont ignored_exceptionst Lockt lock( t selft argst kwargsR ( ( s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyR s
i i c C@ s
| | _ d S( sc Set the ``sync_event`` event used to synchronize exception catching.
When the thread uses an event to synchronize itself with another thread
(setting it when the other thread can wake up from a ``wait`` call),
the event must be set after catching an exception or the other thread
will hang.
Some threads require multiple events and should set the relevant one
when appropriate.
Note that the event should be initially cleared so the caller can
wait() on him and be released when the thread set the event.
Also note that the thread can use multiple events, setting them as it
progress, while the caller can chose to wait on any of them. What
matters is that there is always one event set so that the caller is
always released when an exception is caught. Re-using the same event is
therefore risky as the thread itself has no idea about which event the
caller is waiting on. If the caller has already been released then a
cleared event won't guarantee that the caller is still waiting on it.
N( R ( R t event( ( s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyR 2 s c C@ sd | j } | j j z9 y | j | Wn | j | n X| j Wd | j j Xd S( s Switch to a new ``sync_event`` and set the current one.
Using this method protects against race conditions while setting a new
``sync_event``.
Note that this allows a caller to wait either on the old or the new
event depending on whether it wants a fine control on what is happening
inside a thread.
:param new: The event that will become ``sync_event``
N( R R t acquireR t sett release( R t newt cur( ( s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyt switch_and_setJ s
c @ sO d k r d | _ n3 t t t f rB f d | _ n | _ d S( sά Declare which exceptions will be ignored.
:param ignored: Can be either:
- None: all exceptions will be raised,
- an exception class: the instances of this class will be ignored,
- a tuple of exception classes: the instances of any class of the
list will be ignored,
- a callable: that will be passed the exception object
and should return True if the exception should be ignored
c @ s
t | S( N( t
isinstance( t e( t ignored( s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyt <lambda>w s N( R
R R t Exceptiont tuple( R R ( ( R s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyt set_ignored_exceptionsh s
c C@ sV | j j z4 y t t | j Wn t j | _ n XWd | j j Xd S( s. Overrides Thread.run to capture any exception.N( R t clearR R t runt syst exc_infoR R ( R ( ( s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyR! { s
c C@ su t t | j | | j d k rq | j \ } } } d | _ | j d k s_ | j | rq | | | qq n d S( s³ Overrides Thread.join to raise any exception caught.
Calling join(timeout=0) will raise the caught exception or return None
if the thread is still alive.
N( R R t joinR R
R ( R t timeoutt exc_classt exc_valuet exc_tb( ( s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyR$ s c C@ s | j d d d S( sY Raise the caught exception.
This does nothing if no exception occurred.
R% i N( R$ ( R ( ( s3 /usr/lib/python2.7/dist-packages/bzrlib/cethread.pyt pending_exception s ( i i N( t __name__t
__module__t __doc__R R"