Skip to content
Discussion options

You must be logged in to vote

There are multiple ways to approach what you are trying to do. Either using async I/O to achieve concurrency on the Python side. Or by starting a new thread on the Rust side to sleep and print after the delay.

Note that this implies that you need to share your pyclass with that thread, e.g. by taking slf: Py<Self> as the self parameter and passing that to the background which will then have to use Python::with_gil to acquire the GIL before accessing the properties of you pyclass, e.g.

// Print the informations after 10 seconds
fn display(slf: Py<Self>, py: Python<'_>) {
    let cloned = slf.clone_ref(py);
    std::thread::spawn(move || {
        println!("Wait 10 seconds before print info…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@cyrus937
Comment options

@adamreichold
Comment options

Answer selected by cyrus937
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants