sourmash-bio / sourmash_plugin_branchwater

fast, multithreaded sourmash operations: search, compare, and gather.
GNU Affero General Public License v3.0
13 stars 2 forks source link

enable CTRL-C in rust code? #40

Open ctb opened 10 months ago

bluegenes commented 10 months ago

+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 commented 9 months ago

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 commented 1 month ago

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
  2. Include use pyo3::prelude::*; and call py.check_signals in main function:
ccbaumler commented 1 month ago

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 commented 1 month ago

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 ;)