Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable CTRL-C in rust code? #40

Open
ctb opened this issue Aug 23, 2023 · 5 comments · May be fixed by #387
Open

enable CTRL-C in rust code? #40

ctb opened this issue Aug 23, 2023 · 5 comments · May be fixed by #387

Comments

@ctb
Copy link
Collaborator

ctb commented Aug 23, 2023

No description provided.

@bluegenes
Copy link
Contributor

bluegenes commented Sep 1, 2023

+1!

a potential approach using Arc

in Cargo.toml:

[dependencies]
ctrlc = "3.4.1"
    // Set up a flag to indicate when to terminate
    let terminate = Arc::new(AtomicBool::new(false));
    let terminate_clone = terminate.clone();

    ctrlc::set_handler(move || {
        terminate_clone.store(true, Ordering::SeqCst);
        println!("Ctrl-C received! Cleaning up...");
    }).expect("Error setting Ctrl-C handler");

Then, in each function, use this loop:

 while !terminate.load(Ordering::SeqCst) {
        // fn code...
    }

@bluegenes
Copy link
Contributor

bluegenes commented Sep 11, 2023

if reading zips to pathlists, need to make sure temp_dir gets properly deleted. It should happen automatically when the variable goes out of scope, but maybe include a temp_dir.close() just in case?

@bluegenes
Copy link
Contributor

bluegenes commented May 10, 2024

so there's a much simpler way via pyo3! I just enabled this in the directsketch plugin:

  1. Pass in py /_py from lib to main function
  1. Include use pyo3::prelude::*; and call py.check_signals in main function:

@ccbaumler
Copy link

While running snakemake --profile, the SLURM jobs running rust code like manysketch or directsketch will continue after the workflow is stopped from a workflow error.
The config.yaml I was using may be found here -> https://github.com/dib-lab/portable-snakemake-workflows/blob/main/dotfiles/README.md

$ snakemake --version
7.32.4

@ctb
Copy link
Collaborator Author

ctb commented May 24, 2024

my guess is that this behavior is related to Rust multithreaded apps not responding to signals properly, which is why I suggested colton post it here ;)

@ctb ctb linked a pull request Jul 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants