Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to use async handler #387

Open
Chribati opened this issue Dec 17, 2024 · 0 comments
Open

Not able to use async handler #387

Chribati opened this issue Dec 17, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Chribati
Copy link

Chribati commented Dec 17, 2024

RunPod claims to support async handlers; however, when I define my handler function as async def, I receive the following warning

RuntimeWarning: coroutine 'handler' was never awaited

This suggests that RunPod is not properly awaiting the async handler, causing it to fail during execution.

Steps to reproduce the behavior:

  1. Define an async handler function as documented:
import runpod
import asyncio

async def handler(job):
    await asyncio.sleep(1)  # Simulate async work
    return {"message": "Test Complete"}

if __name__ == '__main__':
    runpod.serverless.start({"handler": handler})
  1. Deploy this code in RunPod (serverless environment) using docker.
  2. Trigger the handler with a test input payload.

The warning coroutine 'handler' was never awaited appears in the logs.
The handler does not execute as expected.

  • Python Version: 3.11
  • Runpod latest
  • Image built for --platform linux/amd64

I've also tried to trigger the handling function inside my handler using

asyncio.create_task

and this leads to me able to send requests and it works, however at this line of code, where I send multiple requests to an API as chunks, a asyncio.CancelError Exception gets thrown and the code exists with code 0

await asyncio.gather(*chunk, return_exceptions=True)

I think the event loop from runpod doesn't allow such a behavior?
If I could define the handler function as async, the problem would not appear!

@Chribati Chribati added the bug Something isn't working label Dec 17, 2024
@Chribati Chribati changed the title Not able to use async Handler in my app Not able to use async Handler Dec 17, 2024
@Chribati Chribati changed the title Not able to use async Handler Not able to use async andler Dec 17, 2024
@Chribati Chribati changed the title Not able to use async andler Not able to use async handler Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants