f _c@sdZddlZddlZddlmZmZmZmZgdZddddZ d d Z d d Z d dZ GdddZ ddZddZGdddZeZGdddeZGdddeZdS)z"Subinterpreters High Level Module.iN) ChannelErrorChannelNotFoundErrorChannelEmptyError is_shareable) Interpreter get_currentget_maincreatelist_all SendChannel RecvChannelcreate_channellist_all_channelsrrrrTisolatedcCstj|d}t||dS)z'Return a new (idle) Python interpreter.r ) _interpretersrr)ridr2/usr/lib64/python3.10/test/support/interpreters.pyrs rcCddtDS)z!Return all existing interpreters.cSsg|] }t|qSr)r).0rrrr zlist_all..)rrrrrrrrcCt}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.Nr cCs.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)z=Nr)rZkZvrrrZ 8rz'Interpreter.__repr__..z(z, ))Zdictrrr Zitemstype__name__Zjoin)r!ZdataZkwargsrrr__repr__6szInterpreter.__repr__cC t|jSNZhashrr!rrr__hash__;zInterpreter.__hash__cCst|tstS|j|jkSr()rrNotImplementedrr!Zotherrrr__eq__>s zInterpreter.__eq__cC|jSr(rr*rrrrDrzInterpreter.idcCs|jdurt|j|_|jSr()r rZ is_isolatedrr*rrrrHs zInterpreter.isolatedcC t|jS)z.)rZchannel_list_allrrrrr nsr c@s<eZdZdZddZddZddZdd Zed d Z d S) _ChannelEndz/The base class for RecvChannel and SendChannel.cCs(t|ttjfstd|||_dSr)rrrZ ChannelIDrr)r!rrrrr"wsz_ChannelEnd.__init__cCst|jdt|jdS)Nz(id=r#)r$r%rrr*rrrr&|r,z_ChannelEnd.__repr__cCr'r(r)r*rrrr+r,z_ChannelEnd.__hash__cCs2t|trt|ts&tSt|ts&tS|j|jkSr()rr r-r rr.rrrr/s    z_ChannelEnd.__eq__cCr0r(r1r*rrrrrz_ChannelEnd.idN) r%r7r8r9r"r&r+r/r:rrrrrr>tsr>c@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)r!r?r@objrrrr<s  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_SETrrAr)r!Zdefaultrrr recv_nowaits zRecvChannel.recv_nowaitN)r%r7r8r9objectr<rErFrrrrr 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. iN)r channel_sendrrBrCr!rDrrrr=szSendChannel.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(). )rrHrrIrrr send_nowaits zSendChannel.send_nowaitN)r%r7r8r9r=rJrrrrr s r )r9rBZ_xxsubinterpretersrrrrrZ__all__rrrrrr r r>rGrEr r rrrrZs 7