Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions crates/pyspark-rs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ pub(crate) fn set_retry_policy(session: &SparkSession, parameters: RetryParamete
}

/// The RPC deadlines of `deadlines`, the deadlines in seconds by the names of the fields of
/// PySpark's `RpcDeadlines`, None for no deadline. A field that the transport has no RPC of, as
/// `get_status`, is not read.
/// PySpark's `RpcDeadlines`, None for no deadline.
pub(crate) fn rpc_deadlines(deadlines: &Bound<'_, PyDict>) -> PyResult<RpcDeadlines> {
let of = |name: &str| -> PyResult<Option<std::time::Duration>> {
let seconds: Option<f64> = match deadlines.get_item(name)? {
Expand All @@ -344,6 +343,7 @@ pub(crate) fn rpc_deadlines(deadlines: &Bound<'_, PyDict>) -> PyResult<RpcDeadli
artifact_status: of("artifact_status")?,
fetch_error_details: of("fetch_error_details")?,
clone_session: of("clone_session")?,
get_status: of("get_status")?,
})
}

Expand Down
16 changes: 16 additions & 0 deletions crates/pyspark-rs/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ pub(crate) fn interruptible_caught<T: Send, E: Send + Into<Box<SparkError>>>(
run_interruptible(py, session, f, true)
}

/// Bring the user context extensions of `session` up to date before a call sends its requests,
/// on the calling thread, with the GIL: the function of `client` that the session keeps (see
/// `PySparkSession::_set_user_context_refresh`), which serializes the `google.protobuf.Any`
/// messages of its lists again, as PySpark serializes them when it builds each request, so that
/// a change of a message in place is sent. Its error is raised, as PySpark raises that of the
/// serialization from the call.
pub(crate) fn refresh_user_context(py: Python<'_>, session: &SparkSession) -> PyResult<()> {
if let Some(refresher) = session.user_context_refresher() {
if let Some(refresh) = refresher.downcast_ref::<Py<PyAny>>() {
refresh.call0(py)?;
}
}
Ok(())
}

/// The wait of [`interruptible_outcome`], of whose results a failed interrupt is the inner one
/// when `catch_interrupt_failure`.
fn run_interruptible<T: Send, E: Send + Into<Box<SparkError>>>(
Expand All @@ -246,6 +261,7 @@ fn run_interruptible<T: Send, E: Send + Into<Box<SparkError>>>(
f: impl FnOnce() -> Result<T, E> + Send,
catch_interrupt_failure: bool,
) -> PyResult<Result<T, Box<SparkError>>> {
refresh_user_context(py, session)?;
let watch = Arc::new(SignalWatch {
session: session.clone(),
interrupted: AtomicBool::new(false),
Expand Down
Loading
Loading