f _@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)ridr2/usr/lib64/python3.10/test/support/interpreters.pyr s r cCsddtDS)z!Return all existing interpreters.cSsg|] }t|qSr)r).0rrrr zlist_all..)rr rrrrr sr cCst}t|S)z)Return the currently running interpreter.)rrrrrrrr!srcCst}t|S)zReturn the main interpreter.)rrrrrrrr'src@sleZdZdZddddZddZdd Zd d Zed d Z eddZ ddZ ddZ ddddZ dS)rzA single Python interpreter.NrcCs.t|ttjfstd|||_||_dSNzid must be an int, got ) isinstanceintrZ InterpreterID TypeError_id _isolated)selfrrrrr__init__0szInterpreter.__init__cCsBtt|j|jd}dd|D}t|jdd|dS)N)rrcss |]\}}|d|VqdS)=Nr)rkvrrr 8rz'Interpreter.__repr__..(z, ))dictrrritemstype__name__join)rdatakwargsrrr__repr__6szInterpreter.__repr__cCs t|jSNhashrrrrr__hash__;szInterpreter.__hash__cCst|tstS|j|jkSr/)rrNotImplementedrrotherrrr__eq__>s zInterpreter.__eq__cCs|jSr/rr2rrrrDszInterpreter.idcCs|jdurt|j|_|jSr/)rrZ is_isolatedrr2rrrrHs zInterpreter.isolatedcCs t|jS)z.)rZchannel_list_allrrrrrnsrc@s<eZdZdZddZddZddZdd Zed d Z d S) _ChannelEndz/The base class for RecvChannel and SendChannel.cCs(t|ttjfstd|||_dSr)rrrZ ChannelIDrr)rrrrrr wsz_ChannelEnd.__init__cCst|jdt|jdS)Nz(id=r&)r)r*rrr2rrrr.|sz_ChannelEnd.__repr__cCs t|jSr/r0r2rrrr3sz_ChannelEnd.__hash__cCs2t|trt|ts&tSt|ts&tS|j|jkSr/)rr r4r rr5rrrr7s    z_ChannelEnd.__eq__cCs|jSr/r8r2rrrrsz_ChannelEnd.idN) r*r=r>r?r r.r3r7r@rrrrrrDtsrDc@s.eZdZdZeddddZefddZdS) r z1The receiving end of a cross-interpreter channel.g{Gz?) _sentinel_delaycCs4t|j|}||ur0t|t|j|}q|S)zReturn the next object from the channel. This blocks until an object has been sent, if none have been sent already. )r channel_recvrtimesleep)rrErFobjrrrrBs  zRecvChannel.recvcCs"|turt|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(). N)_NOT_SETrrGr)rdefaultrrr recv_nowaits zRecvChannel.recv_nowaitN)r*r=r>r?objectrBrKrMrrrrr 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_sendrrHrIrrJrrrrCszSendChannel.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(). )rrPrrQrrr send_nowaits zSendChannel.send_nowaitN)r*r=r>r?rCrRrrrrr s r )r?rHZ_xxsubinterpretersrrrrr__all__r r rrrr rrDrNrKr r rrrrs 7