From 866e7cf3710cca0078ea883c073a2a78aecd4cc6 Mon Sep 17 00:00:00 2001 From: Cherry <13651622+MolotovCherry@users.noreply.github.com> Date: Fri, 21 Jun 2024 22:43:07 -0700 Subject: [PATCH] Make a shared run function in ThreadedVirtualMachine (#5337) --- vm/src/vm/thread.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vm/src/vm/thread.rs b/vm/src/vm/thread.rs index 6ed422ab7..9d29bfae5 100644 --- a/vm/src/vm/thread.rs +++ b/vm/src/vm/thread.rs @@ -93,7 +93,7 @@ impl ThreadedVirtualMachine { /// to the parent thread and then `join()` on the `JoinHandle` (or similar), there is a possibility that /// the current thread will panic as `PyObjectRef`'s `Drop` implementation tries to run the `__del__` /// destructor of a python object but finds that it's not in the context of any vm. - pub fn run(self, f: F) -> R + pub fn run(&self, f: F) -> R where F: FnOnce(&VirtualMachine) -> R, { @@ -118,8 +118,8 @@ impl VirtualMachine { F: Send + 'static, R: Send + 'static, { - let thread = self.new_thread(); - std::thread::spawn(|| thread.run(f)) + let func = self.new_thread().make_spawn_func(f); + std::thread::spawn(func) } /// Create a new VM thread that can be passed to a function like [`std::thread::spawn`]