GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Avoid attaching C API worker templates under the interpreter lock (#9… · RustPython/RustPython@ec299f3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates/capi/src
    • pylifecycle.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎crates/capi/src/pylifecycle.rs‎

Copy file name to clipboardExpand all lines: crates/capi/src/pylifecycle.rs
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn request_vm_from_interpreter() -> ThreadedVirtualMachine {
1919
get_main_interpreter()
2020
.as_ref()
2121
.expect("Interpreter not initialized")
22-
.enter(|vm| vm.new_thread())
22+
.new_thread()
2323
}
2424

2525
#[unsafe(no_mangle)]
@@ -123,4 +123,27 @@ mod tests {
123123

124124
assert!(unsafe { pyo3::ffi::Py_Version } >= 0x030d0000);
125125
}
126+
127+
#[test]
128+
fn requesting_thread_vm_does_not_attach() {
129+
use rustpython_vm::vm::thread::{current_thread_slot, current_vm_is_set};
130+
131+
Python::attach(|py| {
132+
let handle = std::thread::spawn(|| {
133+
let before = (current_vm_is_set(), current_thread_slot().is_some());
134+
let worker_vm = super::request_vm_from_interpreter();
135+
let after = (current_vm_is_set(), current_thread_slot().is_some());
136+
(worker_vm, before, after)
137+
});
138+
let (worker_vm, before, after) = py.detach(|| handle.join().unwrap());
139+
// Drop cloned Python references under the parent interpreter context.
140+
drop(worker_vm);
141+
assert_eq!(before, (false, false), "worker must start outside any VM");
142+
assert_eq!(
143+
after,
144+
(false, false),
145+
"creating a worker VM must not attach under MAIN_INTERP"
146+
);
147+
});
148+
}
126149
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.