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

Drain the Rust client when its last copy in Python is dropped. #1334

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

obi1kenobi
Copy link
Collaborator

If the Python application wants to exit (or the client just gets garbage collected), we want to finish sending any batched requests before proceeding with the GC or app shutdown.

Normally, Python will make sure to shut down any Python-side threads before allowing the program to exit. But it's completely unaware of Rust's own threads, so it can't shut them down or wait for them. This is why we need to explicitly make sure they complete their work and shut down on their own. The Drop trait in Rust runs when the value is dropped, and we ensure we shut down the background threads only when we're certain the only Arc copy of the Rust client is the one we're holding (and which is about to go out of scope).

@obi1kenobi
Copy link
Collaborator Author

In an ideal world, we'd rework the langsmith-tracing-client::client::blocking::TracingClient to take care of its own draining when it's getting dropped.

But that felt like a much bigger piece of work that will have to touch a lot more code. This PR will fix the immediate problem to get Rust-in-Python unblocked, while we work on a cleaner long-term fix.

@obi1kenobi obi1kenobi merged commit 7423b35 into main Dec 12, 2024
20 checks passed
@obi1kenobi obi1kenobi deleted the pg/drain-rust-client branch December 12, 2024 23:01
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