Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
impl faulthandler
  • Loading branch information
youknowone committed Dec 11, 2025
commit b376dea5cddf0767d9d2fe8c6ab61923fc269779
4 changes: 0 additions & 4 deletions Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,6 @@ def test_dump_ext_modules(self):
for name in ('sys', 'faulthandler'):
self.assertIn(name, modules)

# TODO: RUSTPYTHON, AttributeError: module 'faulthandler' has no attribute 'is_enabled'
@unittest.expectedFailure
def test_is_enabled(self):
orig_stderr = sys.stderr
try:
Expand All @@ -435,8 +433,6 @@ def test_is_enabled(self):
finally:
sys.stderr = orig_stderr

# TODO: RUSTPYTHON, subprocess.CalledProcessError: Command ... returned non-zero exit status 1.
@unittest.expectedFailure
@support.requires_subprocess()
def test_disabled_by_default(self):
# By default, the module should be disabled
Expand Down
17 changes: 15 additions & 2 deletions crates/stdlib/src/faulthandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ pub(crate) use decl::make_module;
#[pymodule(name = "faulthandler")]
mod decl {
use crate::vm::{VirtualMachine, frame::Frame, function::OptionalArg, stdlib::sys::PyStderr};
use std::sync::atomic::{AtomicBool, Ordering};

static ENABLED: AtomicBool = AtomicBool::new(false);

fn dump_frame(frame: &Frame, vm: &VirtualMachine) {
let stderr = PyStderr(vm);
Expand Down Expand Up @@ -39,8 +42,18 @@ mod decl {
}

#[pyfunction]
const fn enable(_args: EnableArgs) {
// TODO
fn enable(_args: EnableArgs) {
ENABLED.store(true, Ordering::Relaxed);
}

#[pyfunction]
fn disable() {
ENABLED.store(false, Ordering::Relaxed);
}

#[pyfunction]
fn is_enabled() -> bool {
ENABLED.load(Ordering::Relaxed)
}

#[derive(FromArgs)]
Expand Down