Skip to content

Commit 7e568b5

Browse files
committed
async
1 parent ce2149d commit 7e568b5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/handler.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,24 @@ async def async_handler(job):
4545
max_concurrency = int(os.getenv("MAX_CONCURRENCY", 100))
4646
print(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
6067
import atexit
6168
atexit.register(engine.shutdown)

0 commit comments

Comments
 (0)