Skip to content

Commit 866e7cf

Browse files
Make a shared run function in ThreadedVirtualMachine (RustPython#5337)
1 parent c10b99b commit 866e7cf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

vm/src/vm/thread.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl ThreadedVirtualMachine {
9393
/// to the parent thread and then `join()` on the `JoinHandle` (or similar), there is a possibility that
9494
/// the current thread will panic as `PyObjectRef`'s `Drop` implementation tries to run the `__del__`
9595
/// destructor of a python object but finds that it's not in the context of any vm.
96-
pub fn run<F, R>(self, f: F) -> R
96+
pub fn run<F, R>(&self, f: F) -> R
9797
where
9898
F: FnOnce(&VirtualMachine) -> R,
9999
{
@@ -118,8 +118,8 @@ impl VirtualMachine {
118118
F: Send + 'static,
119119
R: Send + 'static,
120120
{
121-
let thread = self.new_thread();
122-
std::thread::spawn(|| thread.run(f))
121+
let func = self.new_thread().make_spawn_func(f);
122+
std::thread::spawn(func)
123123
}
124124

125125
/// Create a new VM thread that can be passed to a function like [`std::thread::spawn`]

0 commit comments

Comments
 (0)