MCPcopy Index your code
hub / github.com/RustPython/RustPython / make_spawn_func

Method make_spawn_func

crates/vm/src/vm/thread.rs:540–545  ·  view source on GitHub ↗

Create a `FnOnce()` that can easily be passed to a function like [`std::thread::Builder::spawn`] # Note If you return a `PyObjectRef` (or a type that contains one) from `F`, and don't `join()` on the thread this `FnOnce` runs in, there is a possibility that that thread will panic as `PyObjectRef`'s `Drop` implementation tries to run the `__del__` destructor of a Python object but finds that it's

(self, f: F)

Source from the content-addressed store, hash-verified

538 /// as `PyObjectRef`'s `Drop` implementation tries to run the `__del__` destructor of a
539 /// Python object but finds that it's not in the context of any vm.
540 pub fn make_spawn_func<F, R>(self, f: F) -> impl FnOnce() -> R
541 where
542 F: FnOnce(&VirtualMachine) -> R,
543 {
544 move || self.run(f)
545 }
546
547 /// Run a function in this thread context
548 ///

Callers 3

start_new_threadFunction · 0.80
start_joinable_threadFunction · 0.80
start_threadMethod · 0.80

Calls 1

runMethod · 0.45

Tested by

no test coverage detected