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

Method settimeout

crates/stdlib/src/socket.rs:2226–2247  ·  view source on GitHub ↗
(&self, timeout: Option<ArgIntoFloat>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2224
2225 #[pymethod]
2226 fn settimeout(&self, timeout: Option<ArgIntoFloat>, vm: &VirtualMachine) -> PyResult<()> {
2227 let timeout = match timeout {
2228 Some(t) => {
2229 let f = t.into_float();
2230 if f.is_nan() {
2231 return Err(vm.new_value_error("Invalid value NaN (not a number)"));
2232 }
2233 if f < 0.0 || !f.is_finite() {
2234 return Err(vm.new_value_error("Timeout value out of range"));
2235 }
2236 Some(f)
2237 }
2238 None => None,
2239 };
2240 self.timeout.store(timeout.unwrap_or(-1.0));
2241 // even if timeout is > 0 the socket needs to be nonblocking in order for us to select() on
2242 // it
2243 self.sock()
2244 .map_err(|e| e.into_pyexception(vm))?
2245 .set_nonblocking(timeout.is_some())
2246 .map_err(|e| e.into_pyexception(vm))
2247 }
2248
2249 #[pymethod]
2250 fn getsockopt(

Callers

nothing calls this directly

Calls 8

into_floatMethod · 0.80
sockMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
is_nanMethod · 0.45
is_finiteMethod · 0.45
storeMethod · 0.45
into_pyexceptionMethod · 0.45

Tested by

no test coverage detected