2
jestdotty
46d

Ctrl + c not running Drop traits is also annoying

what's the point then, eh

Comments
  • 1
    Sure. But you probably can impliment the atexit function or at least register the signal handler to do it.
  • 0
    Well, they're only run when the code can actually finish executing. Ctrl+C nukes the process
  • 0
    @jestdotty Just don't assume drop to run. Explicitely call your logic to log/save whatever you want to save on exit

    And that's not a Rust thing, that's just in general. In Java there's no guarentee finalize runs. In C++ theres no guarentee deconstructors or catch blocks run

    Just how it works I guess
  • 1
    @jestdotty It's not useless, it does what it's supposed to

    Fundamentally the issue is that Drop calls are baked into the produced machine code. When you Ctrl+C the program stops executing the normal code. It's not feasible for languages to hook that, figure out where the program stopped, have some sort of stack map to know where everything is, look up which values still exist, query the locations and run the drop impls remotely

    That's just not reasonable to expect
  • 2
    I think it should be possible to catch a HUP and convert it into a program-specific cancelation event, no?
  • 3
    @jestdotty, is there no way to catch/is there no "SIGINT" signal raised? That's how I'm handling it on the c++ side

    std::signal(SIGINT, signalHandle);
  • 1
    @BordedDev It is possible and that's how you'd generally do that. There's even a crate called ctrlc which does exactly that lol
Add Comment