diff --git a/tests/snippets/builtin_thread.py b/tests/snippets/builtin_thread.py new file mode 100644 index 0000000000..e9696cce6d --- /dev/null +++ b/tests/snippets/builtin_thread.py @@ -0,0 +1,3 @@ +import _thread + +assert _thread.TIMEOUT_MAX in [9223372036.0, 4294967.0] diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index 225001c4dc..6cec8bd315 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -5,6 +5,14 @@ use crate::function::PyFuncArgs; use crate::pyobject::PyResult; use crate::vm::VirtualMachine; +#[cfg(not(target_os = "windows"))] +const PY_TIMEOUT_MAX: isize = std::isize::MAX; + +#[cfg(target_os = "windows")] +const PY_TIMEOUT_MAX: isize = 0xffffffff * 1_000_000; + +const TIMEOUT_MAX: f64 = (PY_TIMEOUT_MAX / 1_000_000_000) as f64; + fn rlock_acquire(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult { Ok(vm.get_none()) } @@ -54,5 +62,6 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { "RLock" => rlock_type, "get_ident" => ctx.new_rustfunc(get_ident), "allocate_lock" => ctx.new_rustfunc(allocate_lock), + "TIMEOUT_MAX" => ctx.new_float(TIMEOUT_MAX), }) }