-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
recommended way to execute async functions inside dramatiq actors #528
Comments
I suggest using https://github.com/django/asgiref I use it with such decorator: import dramatiq
from functools import wraps
from asgiref.sync import async_to_sync
def async_task(func):
@wraps(func)
def inner(*args, **kwargs):
return async_to_sync(func)(*args, **kwargs)
return inner
@dramatiq.actor(store_results=True)
@async_task
async def my_task(x, y):
await asyncio.sleep(1)
return x + y I have no problems with it but my use cases are quite simple. |
There is a way to do this as of #536 |
It seems that maybe you can directly use async func in dramatiq. learning form: #536 (comment) @dramatiq.actor(store_results=True)
async def my_task(x, y):
await asyncio.sleep(1)
return x + y |
@Bogdanp I have a question that it seems that dramatiq runs tasks through threading? So in fact the async function will only reduce efficiency? Just a sweet? |
Yes, async support is currently limited to being able to run async actors, but there are no concurrency benefits to doing so at the moment as the workers block on the async actor's execution. |
I have some library code that I want to use that only uses async functions.
Right now I am running a async to sync wrapper to execute those.
It works few times then I start getting error
I am using the following decorator to make async functions as dramatiq actor
Any suggestions to run async functions inside actors?
The text was updated successfully, but these errors were encountered: