o Eh@sdZddlZddlZddlmZmZmZmZgdZddddZ d d Z d d Z d dZ GdddZ ddZddZGdddZeZGdddeZGdddeZdS)z"Subinterpreters High Level Module.N) ChannelErrorChannelNotFoundErrorChannelEmptyError is_shareable) Interpreter get_currentget_maincreatelist_all SendChannel RecvChannelcreate_channellist_all_channelsrrrrTisolatedcCstj|d}t||dS)z'Return a new (idle) Python interpreter.r) _interpretersr r)ridr0/usr/lib/python3.10/test/support/interpreters.pyr s  r cCddtDS)z!Return all existing interpreters.cSsg|]}t|qSr)r).0rrrr szlist_all..)rr rrrrr sr cCt}t|S)z)Return the currently running interpreter.)rrrrrrrr!rcCr)zReturn the main interpreter.)rrrrrrrr'rrc@sleZdZdZddddZddZdd Zd d Zed d Z eddZ ddZ ddZ ddddZ dS)rzA single Python interpreter.NrcCs.t|ttjfstd|||_||_dSNzid must be an int, got ) isinstanceintr InterpreterID TypeError_id _isolated)selfrrrrr__init__0s zInterpreter.__init__cCsBtt|j|jd}dd|D}t|jdd|dS)N)rrcss"|] \}}|d|VqdS)=Nr)rkvrrr 8s z'Interpreter.__repr__..(z, ))dictrr r!itemstype__name__join)r"datakwargsrrr__repr__6szInterpreter.__repr__cC t|jSNhashr r"rrr__hash__; zInterpreter.__hash__cCst|tstS|j|jkSr3)rrNotImplementedr r"otherrrr__eq__>s  zInterpreter.__eq__cC|jSr3r r6rrrrDzInterpreter.idcCs|jdur t|j|_|jSr3)r!r is_isolatedr r6rrrrHs zInterpreter.isolatedcC t|jS)z.)rchannel_list_allrrrrrnsrc@s<eZdZdZddZddZddZdd Zed d Z d S) _ChannelEndz/The base class for RecvChannel and SendChannel.cCs(t|ttjfstd|||_dSr)rrr ChannelIDrr )r"rrrrr#ws z_ChannelEnd.__init__cCst|jdt|jdS)Nz(id=r))r,r-rr r6rrrr1|sz_ChannelEnd.__repr__cCr2r3r4r6rrrr7r8z_ChannelEnd.__hash__cCs4t|tr t|ts tSnt|tstS|j|jkSr3)rr r9r r r:rrrr<s    z_ChannelEnd.__eq__cCr=r3r>r6rrrrr?z_ChannelEnd.idN) r-rIrJrKr#r1r7r<rLrrrrrrRtsrRc@s.eZdZdZeddddZefddZdS) r z1The receiving end of a cross-interpreter channel.g{Gz?) _sentinel_delaycCs:t|j|}||urt|t|j|}||us |S)zReturn the next object from the channel. This blocks until an object has been sent, if none have been sent already. )r channel_recvr timesleep)r"rTrUobjrrrrOs  zRecvChannel.recvcCs"|tur t|jSt|j|S)zReturn the next object from the channel. If none have been sent then return the default if one is provided or fail with ChannelEmptyError. Otherwise this is the same as recv(). )_NOT_SETrrVr )r"defaultrrr recv_nowaits zRecvChannel.recv_nowaitN)r-rIrJrKobjectrOrZr\rrrrr s r c@s eZdZdZddZddZdS)r z/The sending end of a cross-interpreter channel.cCst|j|tddS)z{Send the object (i.e. its data) to the channel's receiving end. This blocks until the object is received. N)r channel_sendr rWrXr"rYrrrrPszSendChannel.sendcCst|j|S)zSend the object to the channel's receiving end. If the object is immediately received then return True (else False). Otherwise this is the same as send(). )rr_r r`rrr send_nowaits zSendChannel.send_nowaitN)r-rIrJrKrPrarrrrr s r )rKrW_xxsubinterpretersrrrrr__all__r r rrrr rrRr]rZr r rrrrs  7