Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyc


/9Nc@sWddlmZddlmZddlmZmZddlmZddlZddl	m
Z
ddlmZddl
mZdd	l
mZdd
lmZmZddlmZmZmZddlmZdd
lmZddlZddlmZmZddlm Z dZ!dZ"dej#fdYZ$dZ%dgZ&dS(i(t
generators(tThread(tQueuetEmpty(tsleepN(t
implements(t
IReactorFDSet(terror(t	posixbase(t
_NO_FILENOt_NO_FILEDESC(tlogtfailuret
threadable(tstyles(tplatformType(tEINTRtEBADF(t_selectcCs#y||=Wntk
rnXdS(N(tKeyError(tdcttvalue((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt
dictRemoveOs
cCs
|dS(N((te((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pytraiseExceptionUstThreadedSelectReactorcBseZdZeedZdZdZdZdZ	dZ
dZdZd	Z
d
ZeZdZdZeZd
ZdZdZdZdZdZdZdZdZdZdZdZddZdZ RS(sVA threaded select() based reactor - runs on all POSIX platforms and on
    Win32.
    cCsstjdi|_i|_t|_t|_d|_d|_	t
jj||j
dd|jdS(Nitaftertshutdown(R
tinittreadstwritesRt
toThreadQueuettoMainThreadtNonetworkerThreadt	mainWakerRtPosixReactorBaset__init__taddSystemEventTriggert_mainLoopShutdown(tself((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyR%^s
				cCs|jjdS(N(twakertwakeUp(R(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyR*iscOs&tjj|||}|j|S(N(RR$t	callLaterR*(R(targstkwttple((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyR+ms
cGs6|jj||f|jdk	r2|jndS(N(R tputR#R!(R(tmsgR,((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt_sendToMainrscGs|jj||fdS(N(RR/(R(tfnR,((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt
_sendToThreadxscCstjd|jj}|jj}|jj|jjx|j|f|j|ffD]e\}}xV|D]N}y#tj|g|g|gdWntjd|qwXd||<qwWqdWdS(Ns1Malformed file descriptor found.  Preening lists.isbad descriptor %si(RR0RtkeysRtcleartselect(R(treaderstwriterstselDicttselListt
selectable((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt_preenDescriptorsInThread|s


+
#cCscy)x"|jj\}}||qWn3tk
r<n#tj}|jd|nXdS(NtFailure(Rtgett
SystemExitRR=R1(R(R2R,tf((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt_workerInThreads
c
Cs.|j}|j}xy/t|j|jg|\}}}PWqtk
rm}tj|jqtk
r}tj|jqt	j
tfk
r}	|	jddkr|r|rdSq|	jdt
krdS|	jdtkr
|jqqXq|jd||dS(sRun one iteration of the I/O monitor loop.

        This will run all selectables who had input or output readiness
        waiting for them.
        iiNtNotify(ii(RRRR4t
ValueErrorRterrR<t	TypeErrorR6RtIOErrorR,RRR1(
R(ttimeoutRRtrtwtignoredtvettetse((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt_doSelectInThreads2			





cCs|j}|j}|j}tj}xh|d|f|d|ffD]H\}}}	x6|D].}
|
|	krqqYn||
||
||	qYWqCWdS(NtdoReadtdoWrite(RRt_doReadOrWriteRtcallWithLogger(R(RHRIRRt_drdwt_logruntselectablestmethodRR;((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt_process_Notifys				.
cCs|jdS(N(R(R(R@((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt_process_FailurescCsH|jdks|jjrDtd|j|_|jjndS(Nttarget(R"R!tisAliveRRAtstart(R(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pytensureWorkerThreadscCsM|j|j||j|jj\}}t|d||dS(Nt	_process_(R3t_doIterationInThreadR\R R>tgetattr(R(RGR0R,((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pytdoThreadIterations
ccs}xv|jrx|j|j}|jo.|}|j|j|dV|jj\}}t|d||qWdS(NR](	trunningtrunUntilCurrentRGR3R^R!R t
get_nowaitR_(R(tt2ttR0R,((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt_interleaves
cOsL|j|||j}||d}||_|j|jdS(s
        interleave(waker) interleaves this reactor with the
        current application by moving the blocking parts of
        the reactor (select() in this case) to a separate
        thread.  This is typically useful for integration with
        GUI applications which have their own event loop
        already running.

        See the module docstring for more information.
        cSs||jdS(N(tnext(R)tloop((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyR#sN(tstartRunningRfR#RgR\(R(R)R,R-RhR#((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt
interleaves	
cCsd|_|jdk	r~|jtt|jyx|jj\}}q8Wnt	k
rdnX|jj
d|_nygx`|jj\}}||jkrt
jdq|tkr|dtkrq||qWnt	k
rnXdS(Ns'Iteration is still in the thread queue!i(R!R#R"R3RR?R*R RcRtjoinRR^RR0(R(R0R,R2((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyR's*	



cCsyOt||}t|dd}|s6t}n|dkrNt}nWn!tjd}tjnX|r|j|||dkndS(NtfilenoiiRO(	R_R!R	R
tsystexc_infoRRDt_disconnectSelectable(R(R;RVtdicttwhythandfn((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyRQs	
cCs'|j|jj|d|jdS(sIAdd a FileDescriptor for notification of data available to read.
        iN(R3Rt__setitem__R*(R(treader((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt	addReader-scCs'|j|jj|d|jdS(sJAdd a FileDescriptor for notification of data available to write.
        iN(R3RRsR*(R(twriter((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt	addWriter3scCs|jt|j|dS(sHRemove a Selectable for notification of data available to read.
        N(R3RR(R(Rt((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pytremoveReader9scCs|jt|j|dS(sIRemove a Selectable for notification of data available to write.
        N(R3RR(R(Rv((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pytremoveWriter>scCs|j|j|jS(N(t
_removeAllRR(R(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt	removeAllCscCs
|jjS(N(RR4(R(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt
getReadersGscCs
|jjS(N(RR4(R(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt
getWritersKscCstjj||jdS(s
        Extend the base stop implementation to also wake up the select thread so
        that C{runUntilCurrent} notices the reactor should stop.
        N(RR$tstopR*(R(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyR~OsicCs|jd||jdS(NtinstallSignalHandlers(RitmainLoop(R(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pytrunXscCsSt}|j|jx3|jrNy|jWqtk
rJPqXqWdS(N(RRjR/RaR>t
StopIteration(R(tq((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyR\s	
(!t__name__t
__module__t__doc__RRR%R*R+R1R3R<RARNRWRXR^R\R`tdoIterationRfRjR'RQRuRwRxRyR{R|R}R~RR(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyRXs<
							
	(					
												cCs't}ddlm}|||S(sIConfigure the twisted mainloop to be run using the select() reactor.
    i(tinstallReactor(Rttwisted.internet.mainR(treactorR((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pytinstallgs	
R('t
__future__Rt	threadingRRRttimeRRmtzope.interfaceRttwisted.internet.interfacesRttwisted.internetRRttwisted.internet.posixbaseR	R
ttwisted.pythonRRR
ttwisted.persistedRttwisted.python.runtimeRR6terrnoRRttwisted.internet.selectreactorRRRR$RRt__all__(((sD/usr/lib/python2.7/dist-packages/twisted/internet/_threadedselect.pyt<module>s*5