88import asyncio
99from ctypes import CDLL , byref , c_char_p , c_int
1010from typing import Any , Callable , List , Dict , Optional
11+ import typing
1112
1213from runpod .version import __version__ as runpod_version
1314from runpod .serverless .modules .rp_logger import RunPodLogger
@@ -31,28 +32,35 @@ def __str__(self) -> str:
3132 return f"CGetJobResult(res_len={ self .res_len } , status_code={ self .status_code } )"
3233
3334
35+ def notregistered ():
36+ """ Function to raise NotImplementedError """
37+ raise RuntimeError ("This function is not registered with the SLS Core." )
3438class Hook : # pylint: disable=too-many-instance-attributes
3539 """ Singleton class for interacting with sls_core.so"""
3640
3741 _instance = None
3842
43+
3944 # C function pointers
40- _get_jobs : Callable = None
41- _progress_update : Callable = None
42- _stream_output : Callable = None
43- _post_output : Callable = None
44- _finish_stream : Callable = None
45+ _get_jobs : Callable = notregistered
46+ _progress_update : Callable = notregistered
47+ _stream_output : Callable = notregistered
48+ _post_output : Callable = notregistered
49+ _finish_stream : Callable = notregistered
4550
4651 def __new__ (cls ):
4752 if Hook ._instance is None :
4853 log .debug ("SLS Core | Initializing Hook." )
4954 Hook ._instance = object .__new__ (cls )
5055 Hook ._initialized = False
56+
5157 return Hook ._instance
5258
5359 def __init__ (self , rust_so_path : Optional [str ] = None ) -> None :
60+
5461 if self ._initialized :
5562 return
63+
5664
5765 if rust_so_path is None :
5866 default_path = os .path .join (
@@ -169,8 +177,6 @@ def finish_stream(self, job_id: str) -> bool:
169177 return bool (self ._finish_stream (
170178 c_char_p (id_bytes ), c_int (len (id_bytes ))
171179 ))
172-
173-
174180# -------------------------------- Process Job ------------------------------- #
175181async def _process_job (config : Dict [str , Any ], job : Dict [str , Any ], hook ) -> Dict [str , Any ]:
176182 """ Process a single job. """
@@ -181,7 +187,7 @@ async def _process_job(config: Dict[str, Any], job: Dict[str, Any], hook) -> Dic
181187 if inspect .isgeneratorfunction (handler ) or inspect .isasyncgenfunction (handler ):
182188 log .debug ("SLS Core | Running job as a generator." )
183189 generator_output = rp_job .run_job_generator (handler , job )
184- aggregated_output = {'output' : []}
190+ aggregated_output : dict [ str , typing . Any ] = {'output' : []}
185191
186192 async for part in generator_output :
187193 log .debug (f"SLS Core | Streaming output: { part } " , job ['id' ])
@@ -210,6 +216,7 @@ async def _process_job(config: Dict[str, Any], job: Dict[str, Any], hook) -> Dic
210216 finally :
211217 log .debug (f"SLS Core | Posting output: { result } " , job ['id' ])
212218 hook .post_output (job ['id' ], result )
219+ return result
213220
214221
215222# ---------------------------------------------------------------------------- #
0 commit comments