Skip to content

Commit 402bef1

Browse files
committed
impl faulthandler
1 parent 945f9fc commit 402bef1

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Lib/test/test_faulthandler.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ def test_dump_ext_modules(self):
411411
for name in ('sys', 'faulthandler'):
412412
self.assertIn(name, modules)
413413

414-
# TODO: RUSTPYTHON, AttributeError: module 'faulthandler' has no attribute 'is_enabled'
415-
@unittest.expectedFailure
416414
def test_is_enabled(self):
417415
orig_stderr = sys.stderr
418416
try:
@@ -435,8 +433,6 @@ def test_is_enabled(self):
435433
finally:
436434
sys.stderr = orig_stderr
437435

438-
# TODO: RUSTPYTHON, subprocess.CalledProcessError: Command ... returned non-zero exit status 1.
439-
@unittest.expectedFailure
440436
@support.requires_subprocess()
441437
def test_disabled_by_default(self):
442438
# By default, the module should be disabled

crates/stdlib/src/faulthandler.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ pub(crate) use decl::make_module;
33
#[pymodule(name = "faulthandler")]
44
mod decl {
55
use crate::vm::{VirtualMachine, frame::Frame, function::OptionalArg, stdlib::sys::PyStderr};
6+
use std::sync::atomic::{AtomicBool, Ordering};
7+
8+
static ENABLED: AtomicBool = AtomicBool::new(false);
69

710
fn dump_frame(frame: &Frame, vm: &VirtualMachine) {
811
let stderr = PyStderr(vm);
@@ -39,8 +42,18 @@ mod decl {
3942
}
4043

4144
#[pyfunction]
42-
const fn enable(_args: EnableArgs) {
43-
// TODO
45+
fn enable(_args: EnableArgs) {
46+
ENABLED.store(true, Ordering::Relaxed);
47+
}
48+
49+
#[pyfunction]
50+
fn disable() {
51+
ENABLED.store(false, Ordering::Relaxed);
52+
}
53+
54+
#[pyfunction]
55+
fn is_enabled() -> bool {
56+
ENABLED.load(Ordering::Relaxed)
4457
}
4558

4659
#[derive(FromArgs)]

0 commit comments

Comments
 (0)