MCPcopy Index your code
hub / github.com/RustPython/RustPython / parse_join_timeout

Method parse_join_timeout

crates/vm/src/stdlib/_thread.rs:1345–1387  ·  view source on GitHub ↗
(
            timeout_obj: Option<crate::PyObjectRef>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1343 }
1344
1345 fn parse_join_timeout(
1346 timeout_obj: Option<crate::PyObjectRef>,
1347 vm: &VirtualMachine,
1348 ) -> PyResult<Option<Duration>> {
1349 const JOIN_TIMEOUT_MAX_SECONDS: i64 = TIMEOUT_MAX_IN_MICROSECONDS / 1_000_000;
1350 let Some(timeout_obj) = timeout_obj else {
1351 return Ok(None);
1352 };
1353
1354 if let Some(t) = timeout_obj.try_index_opt(vm) {
1355 let t: i64 = t?.try_to_primitive(vm).map_err(|_| {
1356 vm.new_overflow_error("timestamp too large to convert to C PyTime_t")
1357 })?;
1358 if !(-JOIN_TIMEOUT_MAX_SECONDS..=JOIN_TIMEOUT_MAX_SECONDS).contains(&t) {
1359 return Err(
1360 vm.new_overflow_error("timestamp too large to convert to C PyTime_t")
1361 );
1362 }
1363 if t < 0 {
1364 return Ok(None);
1365 }
1366 return Ok(Some(Duration::from_secs(t as u64)));
1367 }
1368
1369 if let Some(t) = timeout_obj.try_float_opt(vm) {
1370 let t = t?.to_f64();
1371 if t.is_nan() {
1372 return Err(vm.new_value_error("Invalid value NaN (not a number)"));
1373 }
1374 if !t.is_finite() || !(-TIMEOUT_MAX..=TIMEOUT_MAX).contains(&t) {
1375 return Err(vm.new_overflow_error("timestamp out of range for platform time_t"));
1376 }
1377 if t < 0.0 {
1378 return Ok(None);
1379 }
1380 return Ok(Some(Duration::from_secs_f64(t)));
1381 }
1382
1383 Err(vm.new_type_error(format!(
1384 "'{}' object cannot be interpreted as an integer or float",
1385 timeout_obj.class().name()
1386 )))
1387 }
1388
1389 #[pygetset]
1390 fn ident(&self) -> u64 {

Callers

nothing calls this directly

Calls 9

try_index_optMethod · 0.80
try_to_primitiveMethod · 0.80
try_float_optMethod · 0.80
to_f64Method · 0.80
ErrClass · 0.50
SomeClass · 0.50
containsMethod · 0.45
is_nanMethod · 0.45
is_finiteMethod · 0.45

Tested by

no test coverage detected