
    F\h                         S r SSKrSSKrSSKrSSKJrJrJrJr  / SQrSr	S r
SR                  5       r " S S\5      rS	 rS
 rS rS r\R$                  " 5       r " S S5      rg)z"Subinterpreters High Level Module.    N)InterpreterErrorInterpreterNotFoundErrorNotShareableErroris_shareable)get_currentget_maincreatelist_allr   Interpreterr   r   ExecutionFailedr   create_queueQueue
QueueEmpty	QueueFullc                 X    U S;   a  [        5       nSSKJqJqJqJq  X   $ [        U 5      e)N)r   r   r   r      )r	   r   r   r   )globalsqueuesr	   r   r   r   r   AttributeError)namenss     9/usr/lib/python3.13/test/support/interpreters/__init__.py__getattr__r      s0    CCY	
 	
 xT""    z7
{superstr}

Uncaught in the interpreter:

{formatted}
c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )r   .   zrAn unhandled exception happened during execution.

This is raised from Interpreter.exec() and Interpreter.call().
c                 8  > UR                   nU(       dq  UR                  (       a7  UR                  (       a&  UR                  R                   SUR                   3nO)UR                  R                  =(       d    UR                  n[        TU ]  U5        Xl        g )Nz: )	formattedtypemsg__name__super__init__excinfo)selfr$   r    	__class__s      r   r#   ExecutionFailed.__init__4   sg    || ../r'++?ll++:w{{r   c                    >  U R                   R                  n[        R                  [        TU ]  5       US9$ ! [         a    [        TU ]  5       s $ f = f)N)superstrr   )r$   
errdisplay_EXEC_FAILURE_STRformatr"   __str__	Exception)r%   r   r&   s     r   r-   ExecutionFailed.__str__>   s\    	//I %++*# ,    	%7?$$	%s   9 AA)r$   )	r!   
__module____qualname____firstlineno____doc__r#   r-   __static_attributes____classcell__r&   s   @r   r   r   .   s    
	 	r   r   c                  >    [         R                  " SS9n [        U SS9$ )z'Return a new (idle) Python interpreter.T)reqrefs)_ownsref)_interpretersr	   r   )ids    r   r	   r	   J   s    			d	+BrD))r   c            	      n    [         R                  " SS9 V Vs/ s H  u  p[        XS9PM     snn $ s  snn f )z!Return all existing interpreters.T)require_ready_whence)r:   r
   r   r;   whences     r   r
   r
   P   s?     ,444HJH
 +HJ J Js   1c                  B    [         R                  " 5       u  p[        XS9$ )z)Return the currently running interpreter.r>   )r:   r   r   r@   s     r   r   r   V   s    **,JBr**r   c                      [         R                  " 5       u  pU[         R                  :X  d   [        U5      5       e[	        XS9$ )zReturn the main interpreter.r>   )r:   r   WHENCE_RUNTIMEreprr   r@   s     r   r   r   \   s:    '')JB]111?4<?1r**r   c                   0  ^  \ rS rSrSr\R                  S\R                  S\R                  S\R                  S\R                  S\R                  S0rSU 4S	 jjrS
 rS rS rS rS rS r\S 5       r\S 5       rS rS rSS jrS rS rS rSrU =r$ )r   e   aA  A single Python interpreter.

Attributes:

"id" - the unique process-global ID number for the interpreter
"whence" - indicates where the interpreter was created

If the interpreter wasn't created by this module
then any method that modifies the interpreter will fail,
i.e. .close(), .prepare_main(), .exec(), and .call()
unknownzruntime initzlegacy C-APIzC-APIzcross-interpreter C-APIz_interpreters modulec                  > [        U[        5      (       d  [        SU< 35      e[        U5      nUc.  U(       a  [        R                  nO[        R
                  " U5      nX R                  ;   d   [        U5      5       eUc  U[        R                  :H  n [        U   n[        US5      (       d   e U$ ! [         aK    [        TU ]1  U 5      nU[        U'   Xl        X$l        X4l        U(       a  [        R                   " U5         U$ f = f)Nzid must be an int, got r9   )
isinstanceint	TypeErrorr:   WHENCE_STDLIBrA   _WHENCE_TO_STRrE   _knownhasattrKeyErrorr"   __new___idr?   r9   incref)clsr;   r?   r9   r%   r&   s        r   rR   Interpreter.__new__{   s    "c""5bV<==W?'55'..r2,,,;d7m;,=#>#>>H	)":D4,,,,   	)7?3'DF2JH"L$M$$R(	)s   B7 7ADDc                 L    [        U 5      R                   SU R                   S3$ )N())r   r!   r;   r%   s    r   __repr__Interpreter.__repr__   s$    t*%%&ay22r   c                 ,    [        U R                  5      $ N)hashrS   rZ   s    r   __hash__Interpreter.__hash__   s    DHH~r   c                 $    U R                  5         g r^   )_decrefrZ   s    r   __del__Interpreter.__del__   s    r   c                     U R                   4$ r^   rS   rZ   s    r   __getnewargs__Interpreter.__getnewargs__   s    {r   c                     g r^    rZ   s    r   __getstate__Interpreter.__getstate__   s    r   c                     U R                   (       d  g SU l          [        R                  " U R                  5        g ! [         a     g f = f)NF)r9   r:   decrefrS   r   rZ   s    r   rc   Interpreter._decref   s<    }}	  *' 		s    < 
A	A	c                     U R                   $ r^   rg   rZ   s    r   r;   Interpreter.id   s    xxr   c                 4    U R                   U R                     $ r^   )rN   r?   rZ   s    r   rA   Interpreter.whence   s    ""4<<00r   c                 B    [         R                  " U R                  5      $ )z<Return whether or not the identified interpreter is running.)r:   
is_runningrS   rZ   s    r   rv   Interpreter.is_running   s    ''11r   c                 @    [         R                  " U R                  SS9$ )zuFinalize and destroy the interpreter.

Attempting to destroy the current interpreter results
in an InterpreterError.
Trestrict)r:   destroyrS   rZ   s    r   closeInterpreter.close   s     $$TXX==r   c                f    Ub  [        U40 UD6OUn[        R                  " U R                  USS9  g)zVBind the given values into the interpreter's __main__.

The values must be shareable.
NTry   )dictr:   set___main___attrsrS   )r%   r   kwargss      r   prepare_mainInterpreter.prepare_main   s/    
 $&>T"v((2Er   c                `    [         R                  " U R                  USS9nUb  [        U5      eg)a@  Run the given source code in the interpreter.

This is essentially the same as calling the builtin "exec"
with this interpreter, using the __dict__ of its __main__
module as both globals and locals.

There is no return value.

If the code raises an unhandled exception then an ExecutionFailed
exception is raised, which summarizes the unhandled exception.
The actual exception is discarded because objects cannot be
shared between interpreters.

This blocks the current Python thread until done.  During
that time, the previous interpreter is allowed to run
in other threads.
Try   N)r:   execrS   r   )r%   coder$   s      r   r   Interpreter.exec   s2    $  $$TXXtdC!'** r   c                `    [         R                  " U R                  USS9nUb  [        U5      eg)a~  Call the object in the interpreter with given args/kwargs.

Only functions that take no arguments and have no closure
are supported.

The return value is discarded.

If the callable raises an exception then the error display
(including full traceback) is send back between the interpreters
and an ExecutionFailed exception is raised, much like what
happens with Interpreter.exec().
Try   N)r:   callrS   r   )r%   callabler$   s      r   r   Interpreter.call   s2       $$TXXx$G!'** r   c                `   ^ ^ UU 4S jn[         R                  " US9nUR                  5         U$ )zxReturn a new thread that calls the object in the interpreter.

The return value and any raised exception are discarded.
c                  (   > TR                  T 5        g r^   )r   )r   r%   s   r   task(Interpreter.call_in_thread.<locals>.task   s    IIhr   )target)	threadingThreadstart)r%   r   r   ts   ``  r   call_in_threadInterpreter.call_in_thread   s&    
	 D)		r   )rS   r9   r?   )NNr^   )r!   r0   r1   r2   r3   r:   WHENCE_UNKNOWNrD   WHENCE_LEGACY_CAPIWHENCE_CAPI	WHENCE_XIrM   rN   rR   r[   r`   rd   rh   rl   rc   propertyr;   rA   rv   r|   r   r   r   r   r4   r5   r6   s   @r   r   r   e   s    
 ##Y##^''  ' 9""$:N63   1 12>F+,+(	 	r   r   )r3   r   weakrefr:   r   r   r   r   __all__	_queuemodr   stripr+   r   r	   r
   r   r   WeakValueDictionaryrO   r   rk   r   r   <module>r      s    (     	
# 
EG & 8*J++ 
	$	$	&] ]r   