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

fix: Make logger file sink non-blocking when used with asyncio #4301

Merged
merged 2 commits into from
Oct 28, 2024

Conversation

cbornet
Copy link
Collaborator

@cbornet cbornet commented Oct 28, 2024

The Loguru FileSink is blocking so it is bad to use it in the event loop.
Use instead an AsyncSink wrapping the FileSink to delegate the log writing to the default thread pool.
NB: when the AsyncFileSink is used, logs produced outside of the event loop are not written to the file.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 28, 2024
@github-actions github-actions bot added the bug Something isn't working label Oct 28, 2024
Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

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

LGTM

We will probably need to update the build_flow endpoint as well

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 28, 2024
path=file,
rotation="10 MB", # Log rotation based on file size
)
super().__init__(self.write_async, None, ErrorInterceptor(_defaults.LOGURU_CATCH, -1))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately, we can't get the handle id here. But I don't think this is a big problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, unless we can define it in the logger.configure( call

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Oct 28, 2024
@cbornet cbornet merged commit d53107c into langflow-ai:main Oct 28, 2024
27 checks passed
@cbornet cbornet deleted the async-log-file branch October 28, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants