o
    ;i                  
   @   s  U d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 ddlmZ defd	d
ZdddZeeZdee fddZdee fddZdee fddZdee dee dee deg df fddZedZeed< edZeed< edZeed< daedd ZdS )     )contextmanager)
ContextVar)CallableOptional)synchronize_api)InvalidError   )_ContainerIOManagerreturnc                   C   s   t j S )zReturns if we are currently on the machine launching/deploying a Modal app

    Returns `True` when executed locally on the user's machine.
    Returns `False` when executed from a Modal container in the cloud.
    )r	   
_singleton r   r   T/home/ubuntu/.local/lib/python3.10/site-packages/modal/_runtime/execution_context.pyis_local   s   r   Nc                     s&   t j} | s
td|  I dH  dS )zEnable interactivity with user input inside a Modal container.

    See the [interactivity guide](https://modal.com/docs/guide/developing-debugging#interactivity)
    for more information on how to use this function.
    z2Interactivity only works inside a Modal container.N)r	   r   r   interact)container_io_managerr   r   r   	_interact   s
   r   c                   C       zt  W S  ty   Y dS w )a"  Returns the input ID for the current input.

    Can only be called from Modal function (i.e. in a container context).

    ```python
    from modal import current_input_id

    @app.function()
    def process_stuff():
        print(f"Starting to process {current_input_id()}")
    ```
    N)_current_input_idgetLookupErrorr   r   r   r   current_input_id%   
   
r   c                   C   r   )aE  Returns the function call ID for the current input.

    Can only be called from Modal function (i.e. in a container context).

    ```python
    from modal import current_function_call_id

    @app.function()
    def process_stuff():
        print(f"Starting to process input from {current_function_call_id()}")
    ```
    N)_current_function_call_idr   r   r   r   r   r   current_function_call_id8   r   r   c                   C   s    zt  W S  ty   Y d S w N)_current_attempt_tokenr   r   r   r   r   r   current_attempt_tokenK   s
   
r   	input_idsfunction_call_idsattempt_tokensc                    sx   t | t |  krt |krn J | sJ | d }|d }|d }t|t|t|  fdd}|S )Nr   c                      s"   t  t t  d S r   )r   resetr   r   r   attempt_token_tokenfunction_call_tokeninput_tokenr   r   _reset_current_context_ids`   s   

z<_set_current_context_ids.<locals>._reset_current_context_ids)lenr   setr   r   )r   r   r   input_idfunction_call_idattempt_tokenr%   r   r!   r   _set_current_context_idsS   s   .


r+   r   r   r   Fc                   c   s    da zd V  W da d S da w )NTF)_is_currently_importingr   r   r   r   _import_contexto   s
   r-   )r
   N)
contextlibr   contextvarsr   typingr   r   modal._utils.async_utilsr   modal.exceptionr   r   r	   boolr   r   r   strr   r   r   listr+   r   __annotations__r   r   r,   r-   r   r   r   r   <module>   s6   
	

