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: panics when creating delta tables in threads #2940

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions python/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ use tokio::runtime::Runtime;
pub fn rt() -> &'static Runtime {
static TOKIO_RT: OnceLock<Runtime> = OnceLock::new();
static PID: OnceLock<u32> = OnceLock::new();
match PID.get() {
Some(pid) if pid == &std::process::id() => {} // Reuse the static runtime.
Some(pid) => {
panic!(
"Forked process detected - current PID is {} but the tokio runtime was created by {}. The tokio \
runtime does not support forked processes https://github.com/tokio-rs/tokio/issues/4301. If you are \
seeing this message while using Python multithreading make sure to use the `spawn` or `forkserver` \
mode.",
pid, std::process::id()
);
}
None => {
PID.set(std::process::id())
.expect("Failed to record PID for tokio runtime.");
}
let pid = std::process::id();
let runtime_pid = *PID.get_or_init(|| pid);
if pid != runtime_pid {
panic!(
"Forked process detected - current PID is {} but the tokio runtime was created by {}. The tokio \
runtime does not support forked processes https://github.com/tokio-rs/tokio/issues/4301. If you are \
seeing this message while using Python multithreading make sure to use the `spawn` or `forkserver` \
mode.",
pid, runtime_pid
);
}
TOKIO_RT.get_or_init(|| Runtime::new().expect("Failed to create a tokio runtime."))
}
Expand Down
Loading