File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -45,17 +45,24 @@ async def async_handler(job):
4545max_concurrency = int (os .getenv ("MAX_CONCURRENCY" , 100 ))
4646print (f"MAX_CONCURRENCY { max_concurrency } " )
4747
48- async def main ():
48+ # Use a synchronous handler that wraps the async handler
49+ def handler (job ):
50+ return asyncio .get_event_loop ().run_until_complete (async_handler (job ))
51+
52+ async def init ():
4953 await engine .wait_for_server ()
50- await runpod .serverless .start ({
51- "handler" : async_handler ,
54+
55+ if __name__ == "__main__" :
56+ # Initialize the server
57+ asyncio .get_event_loop ().run_until_complete (init ())
58+
59+ # Start the serverless function with a synchronous handler
60+ runpod .serverless .start ({
61+ "handler" : handler ,
5262 "concurrency_modifier" : lambda x : max_concurrency ,
5363 "return_aggregate_stream" : True
5464 })
5565
56- if __name__ == "__main__" :
57- asyncio .run (main ())
58-
5966# Ensure the server is shut down when the serverless function is terminated
6067import atexit
6168atexit .register (engine .shutdown )
You can’t perform that action at this time.
0 commit comments