
    tni                     ^   d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ g d
Z e            Z ej        dd          Ze                    dedd           e                    dddd           e                    dddd           e                    dedd           e                    dedd           e                    dedd           e                    dedd            d!efd"Zd!efd#Zd!efd$Zd% Zd&e	eef         fd'ZdS )(z
Contains the main entrypoint for the Runpod Serverless Worker.

Arguments can be passed in when the worker is started, and will be passed to the worker.
    N)AnyDict   )__version__   )worker)RunPodLogger)progress_update)startr
   runpod_versionrunpodz#Runpod Serverless Worker Arguments.)progdescriptionz--rp_log_levelzrControls what level of logs are printed to the console.
                    Options: ERROR, WARN, INFO, and DEBUG.)typedefaulthelpz--rp_debugger
store_truezFlag to enable the Debugger.)actionr   r   z--rp_serve_apizFlag to start the API server.z--rp_api_porti@  z$Port to start the FastAPI server on.z--rp_api_concurrencyz%Number of concurrent FastAPI workers.z--rp_api_host	localhostz$Host to start the FastAPI server on.z--test_inputz-Test input for the worker, formatted as JSON.returnc                    t                                           \  }}t          j        d         g|z   t          _        t	          |          | d<   | d         d         r)t          j        | d         d                   | d         d<   | d                             dd          r)t          j        | d         d                   | d         d<   | d         d         r&t          	                    | d         d                    | S )zg
    Sets the config rp_args, removing any recognized arguments from sys.argv.
    Returns: config
    r   rp_args
test_inputtest_outputNrp_log_level)
parserparse_known_argssysargvvarsjsonloadsgetlog	set_level)configargsunknowns      W/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/runpod/serverless/__init__.py_set_config_argsr*   S   s    
 ++--MD'}w&CH T

F9 i& V*.*VI5F|5T*U*Uy,' i]D11 X+/:fY6G6V+W+Wy-( i( 9fY'7888M    c                  \    t          t          j                            dd                    S )zK
    Get the realtime port from the environment variable if it exists.
    RUNPOD_REALTIME_PORT0intosenvironr#    r+   r)   _get_realtime_portr4   m   s#     rz~~4c::;;;r+   c                  \    t          t          j                            dd                    S )zR
    Get the realtime concurrency from the environment variable if it exists.
    RUNPOD_REALTIME_CONCURRENCY1r/   r3   r+   r)   _get_realtime_concurrencyr8   t   s#     rz~~;SAABBBr+   c                 f    ~ ~t                               d           t          j        d           dS )z$
    Handles the SIGINT signal.
    zSIGINT received. Shutting down.r   N)r$   infor   exit)sigframes     r)   _signal_handlerr>   {   s-     	UHH.///HQKKKKKr+   r&   c                    t          dt           d           t          j        t          j        t                     t          j                    | d<   t          |           } t                      }t                      }| d         d         rst                              d           ddlm} |                    |           }|                    | d         d	         | d         d
         | d         d                    dS |rSt                              d| d           ddlm} |                    |           }|                    d||           dS t!          j        |            dS )a  
    Starts the serverless worker.

    config (Dict[str, Any]): Configuration parameters for the worker.

    config["handler"] (Callable): The handler function to run.

    config["rp_args"] (Dict[str, Any]): Arguments for the worker, populated by runtime arguments.
    z*--- Starting Serverless Worker |  Version z ---reference_counter_startr   rp_serve_apizStarting API server.r   )
rp_fastapirp_api_hostrp_api_portrp_api_concurrency)api_hostapi_portapi_concurrencyNz)Starting API server for realtime on port .z0.0.0.0)printr   signalSIGINTr>   timeperf_counterr*   r4   r8   r$   r:   modulesrB   	WorkerAPIstart_uvicornr   main)r&   realtime_portrealtime_concurrencyrB   
api_servers        r)   r   r      s    

K~
K
K
KLLL
M&-111(,(9(;(;F$%f%%F&((M466i( 
'(((''''''))&11
  I&}5I&}5"9-.BC 	! 	
 	
 	

 	 
M]MMMNNN''''''))&11
  "0 	! 	
 	
 	

 	
K
Fr+   ) __doc__argparser!   r1   rK   r   rM   typingr   r   versionr   r    r   modules.rp_loggerr	   modules.rp_progressr
   __all__r$   ArgumentParserr   add_argumentstrr0   dictr*   r4   r8   r>   r   r3   r+   r)   <module>rb      s      				  



          3 3 3 3 3 3       + + + + + + 0 0 0 0 0 0   lnn 
!	 	D
 
 
   	
>	       	'	       	(	       #t2X       		0	       		/	       		8	        4<C < < < <C3 C C C C  -$sCx. - - - - - -r+   