Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
contego / home / tvault / .virtenv / lib / python2.7 / site-packages / swiftclient / multithreading.pyc
Size: Mime:
ó
~˜EYc@sŽddlmZddlZddlZddlmZddlmZdefd„ƒYZ	defd„ƒYZ
d	efd
„ƒYZdS(iÿÿÿÿ(tprint_functionN(tThreadPoolExecutor(t
PriorityQueuet
OutputManagercBs’eZdZdZddd„Zd„Zd„Zd„Zd„Z	d„Z
eed„Zd	„Z
d
„Zdd„Zdd
„Zd„ZRS(s
    One object to manage and provide helper functions for output.

    This object is a context manager and returns itself into the context.  When
    entering the context, two printing threads are created (see below) and they
    are waited on and cleaned up when exiting the context.

    Also, thread-safe printing to two streams is provided.  The
    :meth:`print_msg` method will print to the supplied ``print_stream``
    (defaults to ``sys.stdout``) and the :meth:`error` method will print to the
    supplied ``error_stream`` (defaults to ``sys.stderr``).  Both of these
    printing methods will format the given string with any supplied ``*args``
    (a la printf). On Python 2, Unicode messages are encoded to utf8.

    The attribute :attr:`self.error_count` is incremented once per error
    message printed, so an application can tell if any worker threads
    encountered exceptions or otherwise called :meth:`error` on this instance.
    The swift command-line tool uses this to exit non-zero if any error strings
    were printed.
    icCsU|ptj|_tddƒ|_|p0tj|_tddƒ|_d|_dS(s5
        :param print_stream: The stream to which :meth:`print_msg` sends
                             formatted messages.
        :param error_stream: The stream to which :meth:`error` sends formatted
                             messages.

        On Python 2, Unicode messages are encoded to utf8.
        tmax_workersiiN(	tsyststdouttprint_streamRt
print_pooltstderrterror_streamterror_print_poolterror_count(tselfRR
((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyt__init__0s
	cCs|S(N((R
((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyt	__enter__@scCs0|jj|||ƒ|jj|||ƒdS(N(Rt__exit__R(R
texc_typet	exc_valuet	traceback((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyRCscCs |jj|j||jƒdS(N(Rtsubmitt_writeR(R
tdata((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyt	print_rawGscCsMtjr&|jj|ƒ|jƒntjrI|j|ƒ|jƒndS(N(tsixtPY3tbuffertwritetflushtPY2(R
Rtstream((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyRJs	
	
cGs-|r||}n|jj|j|ƒdS(N(RRt_print(R
tmsgtfmt_args((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyt	print_msgRs
cCsUd|}xD|D]<\}}|r0|r0qn|j|||fjƒƒqWdS(Ns
%%%ds: %%s(R"trstrip(R
titemstoffsettskip_missingttemplatetktv((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pytprint_itemsWs


cGs-|r||}n|jj|j|ƒdS(N(RRt_print_error(R
R R!((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyterror^s
cCs|jS(N(R(R
((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pytget_error_countcscCsY|dkr|j}ntjrEt|tjƒrE|jdƒ}nt|d|ƒdS(Ntutf8tfile(tNoneRRRt
isinstancet	text_typetencodetprint(R
titemR((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyRfs
icCs%|j|7_|j|d|jƒS(NR(RRR
(R
R5tcount((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyR+mscGs3|r||}n|jj|j|ddƒdS(NR6i(RRR+(R
R R!((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pytwarningqs
N(t__name__t
__module__t__doc__tDEFAULT_OFFSETR0RRRRRR"tFalseR*R,R-RR+R7(((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyRs							tMultiThreadingManagercBs5eZdZddddd„Zd„Zd„ZRS(sŒ
    One object to manage context for multi-threading.  This should make
    bin/swift less error-prone and allow us to test this code.
    i
cCsXt|d|ƒ|_t|d|ƒ|_t|d|ƒ|_t|d|ƒ|_dS(s

        :param segment_threads: The number of threads allocated to segment
                                uploads
        :param object_dd_threads: The number of threads allocated to object
                                  download/delete jobs
        :param object_uu_threads: The number of threads allocated to object
                                  upload/update based jobs
        :param container_threads: The number of threads allocated to
                                  container/account level jobs
        RN(tConnectionThreadPoolExecutortsegment_pooltobject_dd_pooltobject_uu_pooltcontainer_pool(R
tcreate_connectiontsegment_threadstobject_dd_threadstobject_uu_threadstcontainer_threads((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyR~s
cCs|S(N((R
((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyR”scCs\|jj|||ƒ|jj|||ƒ|jj|||ƒ|jj|||ƒdS(N(R?RR@RARB(R
RRR((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyR—s(R8R9R:RRR(((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyR=xs	R>cBs eZdZd„Zd„ZRS(s
    A wrapper class to maintain a pool of connections alongside the thread
    pool. We start by creating a priority queue of connections, and each job
    submitted takes one of those connections (initialising if necessary) and
    passes it as the first arg to the executed function.

    At the end of execution that connection is returned to the queue.

    By using a PriorityQueue we avoid creating more connections than required.
    We will only create as many connections as are required concurrently.
    cCs_tƒ|_||_x-td|ƒD]}|jj|dfƒq%Wtt|ƒj|ƒdS(Ni(	Rt_connectionst_create_connectiontrangetputR0tsuperR>R(R
RCRtp((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyRªs
	cs.‡‡‡‡fd†}ttˆƒj|ƒS(Ncs‡d}d}zNˆjjƒ\}}|dkr?ˆjƒ}n|fˆ}ˆ|ˆŽSWd|dk	r‚ˆjj||fƒnXdS(N(R0RHtgetRIRK(tprioritytconnt	conn_args(targstfntkwargsR
(sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pytconn_fn²s
(RLR>R(R
RSRRRTRU((RRRSRTR
sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyR±s(R8R9R:RR(((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyR>žs	(t
__future__RRRtconcurrent.futuresRtsix.moves.queueRtobjectRR=R>(((sO/home/tvault/.virtenv/lib/python2.7/site-packages/swiftclient/multithreading.pyt<module>s_&