%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib64/python2.7/site-packages/tornado/
Upload File :
Create Path :
Current File : //usr/lib64/python2.7/site-packages/tornado/locks.pyc

�
��L]c@�s
dZddlmZmZmZmZdddddgZddlZdd	lm	Z	m
Z
dd
lmZde
fd��YZdefd
��YZde
fd��YZde
fd��YZdefd��YZdefd��YZde
fd��YZdS(sd
.. testsetup:: *

    from tornado import ioloop, gen, locks
    io_loop = ioloop.IOLoop.current()
i(tabsolute_importtdivisiontprint_functiontwith_statementt	ConditiontEventt	SemaphoretBoundedSemaphoretLockN(tgentioloop(tFuturet_TimeoutGarbageCollectorcB�s eZdZd�Zd�ZRS(s�Base class for objects that periodically clean up timed-out waiters.

    Avoids memory leak in a common pattern like:

        while True:
            yield condition.wait(short_timeout)
            print('looping....')
    cC�stj�|_d|_dS(Ni(tcollectionstdequet_waiterst	_timeouts(tself((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt__init__)scC�sM|jd7_|jdkrId|_tjd�|jD��|_ndS(Niidics�s!|]}|j�s|VqdS(N(tdone(t.0tw((s3/usr/lib64/python2.7/site-packages/tornado/locks.pys	<genexpr>3s(RR
RR(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt_garbage_collect-s
	(t__name__t
__module__t__doc__RR(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR s	cB�sAeZdZd�Zd�Zdd�Zdd�Zd�ZRS(s�A condition allows one or more coroutines to wait until notified.

    Like a standard `threading.Condition`, but does not need an underlying lock
    that is acquired and released.

    With a `Condition`, coroutines can wait to be notified by other coroutines:

    .. testcode::

        condition = locks.Condition()

        @gen.coroutine
        def waiter():
            print("I'll wait right here")
            yield condition.wait()  # Yield a Future.
            print("I'm done waiting")

        @gen.coroutine
        def notifier():
            print("About to notify")
            condition.notify()
            print("Done notifying")

        @gen.coroutine
        def runner():
            # Yield two Futures; wait for waiter() and notifier() to finish.
            yield [waiter(), notifier()]

        io_loop.run_sync(runner)

    .. testoutput::

        I'll wait right here
        About to notify
        Done notifying
        I'm done waiting

    `wait` takes an optional ``timeout`` argument, which is either an absolute
    timestamp::

        io_loop = ioloop.IOLoop.current()

        # Wait up to 1 second for a notification.
        yield condition.wait(timeout=io_loop.time() + 1)

    ...or a `datetime.timedelta` for a timeout relative to the current time::

        # Wait up to 1 second.
        yield condition.wait(timeout=datetime.timedelta(seconds=1))

    The method raises `tornado.gen.TimeoutError` if there's no notification
    before the deadline.
    cC�s)tt|�j�tjj�|_dS(N(tsuperRRR
tIOLooptcurrenttio_loop(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyRmscC�s>d|jjf}|jr6|dt|j�7}n|dS(Ns<%ss waiters[%s]t>(t	__class__RRtlen(Rtresult((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt__repr__qs	c�srt���jj��|rn��fd�}tjj���j||���j��fd��n�S(s�Wait for `.notify`.

        Returns a `.Future` that resolves ``True`` if the condition is notified,
        or ``False`` after a timeout.
        c�s�jt��j�dS(N(t
set_resulttFalseR((Rtwaiter(s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt
on_timeout�s
c�s
�j��S(N(tremove_timeout(t_(Rttimeout_handle(s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt<lambda>�s(RRtappendR
RRtadd_timeouttadd_done_callback(RttimeoutR&((RRR)R%s3/usr/lib64/python2.7/site-packages/tornado/locks.pytwaitws	icC�ssg}xH|rP|jrP|jj�}|j�s	|d8}|j|�q	q	Wx|D]}|jt�qXWdS(sWake ``n`` waiters.iN(RtpopleftRR+R#tTrue(RtntwaitersR%((s3/usr/lib64/python2.7/site-packages/tornado/locks.pytnotify�s

cC�s|jt|j��dS(sWake all waiters.N(R4R R(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt
notify_all�sN(	RRRRR"tNoneR/R4R5(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR6s5		cB�sGeZdZd�Zd�Zd�Zd�Zd�Zdd�Z	RS(soAn event blocks coroutines until its internal flag is set to True.

    Similar to `threading.Event`.

    A coroutine can wait for an event to be set. Once it is set, calls to
    ``yield event.wait()`` will not block unless the event has been cleared:

    .. testcode::

        event = locks.Event()

        @gen.coroutine
        def waiter():
            print("Waiting for event")
            yield event.wait()
            print("Not waiting this time")
            yield event.wait()
            print("Done")

        @gen.coroutine
        def setter():
            print("About to set the event")
            event.set()

        @gen.coroutine
        def runner():
            yield [waiter(), setter()]

        io_loop.run_sync(runner)

    .. testoutput::

        Waiting for event
        About to set the event
        Not waiting this time
        Done
    cC�st�|_dS(N(Rt_future(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�scC�s&d|jj|j�rdndfS(Ns<%s %s>tsettclear(RRtis_set(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR"�scC�s
|jj�S(s-Return ``True`` if the internal flag is true.(R7R(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR:�scC�s&|jj�s"|jjd�ndS(s�Set the internal flag to ``True``. All waiters are awakened.

        Calling `.wait` once the flag is set will not block.
        N(R7RR#R6(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR8�scC�s"|jj�rt�|_ndS(ssReset the internal flag to ``False``.
        
        Calls to `.wait` will block until `.set` is called.
        N(R7RR(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR9�scC�s*|dkr|jStj||j�SdS(s�Block until the internal flag is true.

        Returns a Future, which raises `tornado.gen.TimeoutError` after a
        timeout.
        N(R6R7R	twith_timeout(RR.((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR/�sN(
RRRRR"R:R8R9R6R/(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�s%					t_ReleasingContextManagercB�s)eZdZd�Zd�Zd�ZRS(s�Releases a Lock or Semaphore at the end of a "with" statement.

        with (yield semaphore.acquire()):
            pass

        # Now semaphore.release() has been called.
    cC�s
||_dS(N(t_obj(Rtobj((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�scC�sdS(N((R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt	__enter__�scC�s|jj�dS(N(R=trelease(Rtexc_typetexc_valtexc_tb((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt__exit__�s(RRRRR?RD(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR<�s		cB�sGeZdZdd�Zd�Zd�Zdd�Zd�ZeZ	RS(s�A lock that can be acquired a fixed number of times before blocking.

    A Semaphore manages a counter representing the number of `.release` calls
    minus the number of `.acquire` calls, plus an initial value. The `.acquire`
    method blocks if necessary until it can return without making the counter
    negative.

    Semaphores limit access to a shared resource. To allow access for two
    workers at a time:

    .. testsetup:: semaphore

       from collections import deque

       from tornado import gen, ioloop
       from tornado.concurrent import Future

       # Ensure reliable doctest output: resolve Futures one at a time.
       futures_q = deque([Future() for _ in range(3)])

       @gen.coroutine
       def simulator(futures):
           for f in futures:
               yield gen.moment
               f.set_result(None)

       ioloop.IOLoop.current().add_callback(simulator, list(futures_q))

       def use_some_resource():
           return futures_q.popleft()

    .. testcode:: semaphore

        sem = locks.Semaphore(2)

        @gen.coroutine
        def worker(worker_id):
            yield sem.acquire()
            try:
                print("Worker %d is working" % worker_id)
                yield use_some_resource()
            finally:
                print("Worker %d is done" % worker_id)
                sem.release()

        @gen.coroutine
        def runner():
            # Join all workers.
            yield [worker(i) for i in range(3)]

        io_loop.run_sync(runner)

    .. testoutput:: semaphore

        Worker 0 is working
        Worker 1 is working
        Worker 0 is done
        Worker 2 is working
        Worker 1 is done
        Worker 2 is done

    Workers 0 and 1 are allowed to run concurrently, but worker 2 waits until
    the semaphore has been released once, by worker 0.

    `.acquire` is a context manager, so ``worker`` could be written as::

        @gen.coroutine
        def worker(worker_id):
            with (yield sem.acquire()):
                print("Worker %d is working" % worker_id)
                yield use_some_resource()

            # Now the semaphore has been released.
            print("Worker %d is done" % worker_id)
    icC�s;tt|�j�|dkr.td��n||_dS(Nis$semaphore initial value must be >= 0(RRRt
ValueErrort_value(Rtvalue((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyREscC�sztt|�j�}|jdkr*dndj|j�}|jrcdj|t|j��}ndj|dd!|�S(Nitlockedsunlocked,value:{0}s{0},waiters:{1}s<{0} [{1}]>ii����(RRR"RFtformatRR (Rtrestextra((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR"Ls	cC�sd|jd7_xN|jr_|jj�}|j�s|jd8_|jt|��PqqWdS(s*Increment the counter and wake one waiter.iN(RFRR0RR#R<(RR%((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR@Tsc�s�t���jdkr=�jd8_�jt���ne�jj��|r���fd�}tjj���j	||���j
��fd��n�S(s�Decrement the counter. Returns a Future.

        Block if the counter is zero and wait for a `.release`. The Future
        raises `.TimeoutError` after the deadline.
        iic�s!�jtj���j�dS(N(t
set_exceptionR	tTimeoutErrorR((RR%(s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR&rsc�s
�j��S(N(R'(R((RR)(s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR*xs(RRFR#R<RR+R
RRR,R-(RR.R&((RRR)R%s3/usr/lib64/python2.7/site-packages/tornado/locks.pytacquirees	cC�std��dS(NsPUse Semaphore like 'with (yield semaphore.acquire())', not like 'with semaphore'(tRuntimeError(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR?{sN(
RRRRR"R@R6RNR?RD(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�sK			cB�s#eZdZdd�Zd�ZRS(s:A semaphore that prevents release() being called too many times.

    If `.release` would increment the semaphore's value past the initial
    value, it raises `ValueError`. Semaphores are mostly used to guard
    resources with limited capacity, so a semaphore released too many times
    is a sign of a bug.
    icC�s&tt|�jd|�||_dS(NRG(RRRt_initial_value(RRG((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�scC�s8|j|jkr!td��ntt|�j�dS(s*Increment the counter and wake one waiter.s!Semaphore released too many timesN(RFRPRERRR@(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR@�s(RRRRR@(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�scB�sDeZdZd�Zd�Zdd�Zd�Zd�ZeZ	RS(sEA lock for coroutines.

    A Lock begins unlocked, and `acquire` locks it immediately. While it is
    locked, a coroutine that yields `acquire` waits until another coroutine
    calls `release`.

    Releasing an unlocked lock raises `RuntimeError`.

    `acquire` supports the context manager protocol:

    >>> from tornado import gen, locks
    >>> lock = locks.Lock()
    >>>
    >>> @gen.coroutine
    ... def f():
    ...    with (yield lock.acquire()):
    ...        # Do something holding the lock.
    ...        pass
    ...
    ...    # Now the lock is released.
    cC�stdd�|_dS(NRGi(Rt_block(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�scC�sd|jj|jfS(Ns<%s _block=%s>(RRRQ(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR"�s	cC�s|jj|�S(s�Attempt to lock. Returns a Future.

        Returns a Future, which raises `tornado.gen.TimeoutError` after a
        timeout.
        (RQRN(RR.((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyRN�scC�s5y|jj�Wntk
r0td��nXdS(s�Unlock.

        The first coroutine in line waiting for `acquire` gets the lock.

        If not locked, raise a `RuntimeError`.
        srelease unlocked lockN(RQR@RERO(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR@�s
cC�std��dS(Ns7Use Lock like 'with (yield lock)', not like 'with lock'(RO(R((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR?�sN(
RRRRR"R6RNR@R?RD(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyR�s				(Rt
__future__RRRRt__all__R
ttornadoR	R
ttornado.concurrentRtobjectRRRR<RRR(((s3/usr/lib64/python2.7/site-packages/tornado/locks.pyt<module>s"dM�

Zerion Mini Shell 1.0