Make a shared run function in ThreadedVirtualMachine (#5337)

This commit is contained in:
Cherry authored and GitHub committed 2024-06-22 14:43:07 +09:00
1 parent c10b99b29a
commit 866e7cf371
1 file changed
+3 -3
+3 -3
View File
@@ -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<F, R>(self, f: F) -> R
pub fn run<F, R>(&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`]