Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d68313

Browse files
authored
sys.setswitchinterval (#5817)
1 parent e27263a commit 5d68313

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

Lib/test/test_functools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,8 +1691,6 @@ def f(zomg: 'zomg_annotation'):
16911691
for attr in self.module.WRAPPER_ASSIGNMENTS:
16921692
self.assertEqual(getattr(g, attr), getattr(f, attr))
16931693

1694-
# TODO: RUSTPYTHON
1695-
@unittest.expectedFailure
16961694
@threading_helper.requires_working_threading()
16971695
def test_lru_cache_threaded(self):
16981696
n, m = 5, 11

Lib/test/test_sys.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ def test_getdefaultencoding(self):
260260
# testing sys.settrace() is done in test_sys_settrace.py
261261
# testing sys.setprofile() is done in test_sys_setprofile.py
262262

263-
# TODO: RUSTPYTHON, AttributeError: module 'sys' has no attribute 'setswitchinterval'
264-
@unittest.expectedFailure
265263
def test_switchinterval(self):
266264
self.assertRaises(TypeError, sys.setswitchinterval)
267265
self.assertRaises(TypeError, sys.setswitchinterval, "a")

Lib/test/test_syslog.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ def test_openlog_noargs(self):
5555
syslog.openlog()
5656
syslog.syslog('test message from python test_syslog')
5757

58-
# TODO: RUSTPYTHON; AttributeError: module 'sys' has no attribute 'getswitchinterval'
59-
@unittest.expectedFailure
6058
@threading_helper.requires_working_threading()
6159
def test_syslog_threaded(self):
6260
start = threading.Event()

Lib/test/test_threading.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ def child():
412412
b"Woke up, sleep function is: <built-in function sleep>")
413413
self.assertEqual(err, b"")
414414

415-
# TODO: RUSTPYTHON
416-
@unittest.expectedFailure
417415
def test_enumerate_after_join(self):
418416
# Try hard to trigger #1703448: a thread is still returned in
419417
# threading.enumerate() after it has been join()ed.

vm/src/stdlib/sys.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,25 @@ mod sys {
799799
crate::vm::thread::COROUTINE_ORIGIN_TRACKING_DEPTH.with(|cell| cell.get()) as _
800800
}
801801

802+
#[pyfunction]
803+
fn getswitchinterval(vm: &VirtualMachine) -> f64 {
804+
// Return the stored switch interval
805+
vm.state.switch_interval.load()
806+
}
807+
808+
// TODO: vm.state.switch_interval is currently not used anywhere in the VM
809+
#[pyfunction]
810+
fn setswitchinterval(interval: f64, vm: &VirtualMachine) -> PyResult<()> {
811+
// Validate the interval parameter like CPython does
812+
if interval <= 0.0 {
813+
return Err(vm.new_value_error("switch interval must be strictly positive".to_owned()));
814+
}
815+
816+
// Store the switch interval value
817+
vm.state.switch_interval.store(interval);
818+
Ok(())
819+
}
820+
802821
#[derive(FromArgs)]
803822
struct SetAsyncgenHooksArgs {
804823
#[pyarg(any, optional)]

vm/src/vm/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub struct PyGlobalState {
106106
pub after_forkers_child: PyMutex<Vec<PyObjectRef>>,
107107
pub after_forkers_parent: PyMutex<Vec<PyObjectRef>>,
108108
pub int_max_str_digits: AtomicCell<usize>,
109+
pub switch_interval: AtomicCell<f64>,
109110
}
110111

111112
pub fn process_hash_secret_seed() -> u32 {
@@ -189,6 +190,7 @@ impl VirtualMachine {
189190
after_forkers_child: PyMutex::default(),
190191
after_forkers_parent: PyMutex::default(),
191192
int_max_str_digits,
193+
switch_interval: AtomicCell::new(0.005),
192194
}),
193195
initialized: false,
194196
recursion_depth: Cell::new(0),

0 commit comments

Comments
 (0)