Skip to content

Offload synchronous actions in ctx.run via asyncio.to_thread to prevent event loop blocking #47

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

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

ouatu-ro
Copy link
Contributor

This change ensures that:

  • Sync functions passed to ctx.run are executed in a background thread.
  • The event loop remains unblocked, maintaining the performance of concurrent handlers.
  • The behavior is consistent with other async frameworks such as FastAPI.

Related to #46

@ouatu-ro ouatu-ro changed the title Use asyncio.to_thread for synchronous action execution in ServerInvocationContext Offload synchronous actions in ctx.run via asyncio.to_thread to prevent event loop blocking Mar 13, 2025
Copy link
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @ouatu-ro 🎉

LGTM!

@igalshilman igalshilman merged commit b409048 into restatedev:main Mar 13, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants