mς =γΈEc@spdZdkZdkZdaeiƒZdagZfdd„Z d„Z de ddd„Z e e_ dS(s±Manage the asyncore mainloop in a multi-threaded app. In a multi-threaded application, only a single thread runs the asyncore mainloop. This thread (the "mainloop thread") may not start the mainloop before another thread needs to perform an async action that requires it. As a result, other threads need to coordinate with the mainloop thread to find out whether the mainloop is running. This module implements a callback mechanism that allows other threads to be notified when the mainloop starts. A thread calls register_loop_callback() to register interest. When the mainloop thread calls loop(), each registered callback will be called with the socket map as its first argument. NcCs^tiƒzBtdj o|t||phŽnti|||fƒWdti ƒXdS(sξRegister callback function to be called when mainloop starts. The callable object callback will be invokved when the mainloop starts. If the mainloop is currently running, the callback will be invoked immediately. The callback will be called with a single argument, the mainloop socket map, unless the optional args or kw arguments are used. args defines a tuple of extra arguments to pass after the socket map. kw defines a dictionary of keyword arguments. N( t _loop_locktacquiret_loopingtNonetcallbacktargstkwt_loop_callbackstappendtrelease(RRR((t9/data/zmath/zope/lib/python/ThreadedAsync/LoopCallback.pytregister_loop_callback)s   cCsAx:ttƒD],\}}|d|jot|=dSq q WdS(scRemove a callback function registered earlier. This is useful if loop() was never called. iN(t enumerateRtitvalueR(RR R((R tremove_loop_callback>s  f30.0cCsWda|djo ti}n|o*ttdƒo ti}qZti }n ti }t i ƒzE|ax8to0tiƒ\}}}||||phŽqpWWdt iƒX|djo-xj|otdjo|||ƒqΗWnAx=|o5|djo(tdjo|||ƒ|d8}qτWt i ƒz daWdt iƒXdS(Ntpollii(Rt exit_statustmaptasyncoret socket_maptuse_pollthasattrtselecttpoll3tpoll_funtpoll2RRRRRtpoptcbRRR tcountttimeout(RRRRRRRR((R tloopPs@         !   ( t__doc__RtthreadRRt allocate_lockRRRR RtFalseR(RRR!R RRR((R t?s    C