-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add a way to exit a thread early and run destructors, akin to panic!(), without displaying an error message to the user #1089
Comments
I don't think introducing a separate panicking mechanism is a good idea. I'm not sure where the panic message is printed, but I think the intended way to achieve this (if you really can't add early returns up the call stack) is to spawn the thread with a wrapper which silently ignores panics. The return value of panicking() should still be true. |
There’s currently no way to make I think it would be great if |
@Diggsey how would you achieve that? http://is.gd/aDT4F7 prints the panic message. @nagisa I agree, |
@filsmick I didn't mean it was actually possible today, unfortunately, just that in the long term that's likely how it should be done (rather than introducing a new unwinding mechanism, to fix the problems with the existing one). |
@Diggsey I don't think it's a good idea. Rust emphasizes performance, and spawning a new thread just to avoid logging isn't exactly efficient. There is no need to introduce a new unwinding mechanism either. The idea is to remove logging from std::rt::unwind::begin_unwind_inner, wrap its functionality in another function that will provide logging and be called by Or, to preserve backward compatibility, add a new function without logging and deprecate the old one. That's not "a new unwinding mechanism", that's moving functionality out of the old one and deprecating it. |
@filsmick edit: |
My bad. I thought you meant spawn a new thread around an existing one to somehow catch the panic without logging it. I think that's a good idea, clean and flexible. It could be also be implemented easily in terms of |
I've thought about it, and the best way to do this would be to make No deprecation, no addition of a new panic mechanism, just what makes the most sense: if you want a message to be displayed, you should be passing it as an argument to the macro anyway! |
#1328 being merged should help with this! |
I believe this is basically handled by |
Unwinding the stack and running destructors is useful to abort a particular thread, without having to add early returns all the way up the call stack.
panic!()
provides this functionality, but also displays a message to the user, even if the panic is caught, which is disturbing: you don't want to expose debugging info such as line number to the end user.This would provide a clean exit mechanism while avoiding adding functionality that's already there, as you get (correct me if I'm wrong) similar results with either early returns and
panic!()
: the stack unwinds, destructors are run, and the thread exits cleanly. This is not a problem for single-threaded programs, which can usestd::process::exit
and let the OS clean up resources, but would be useful for multi-threaded programs.Essentially, I'm proposing a silent version of
panic!()
,that does not actually panic (does not change the return value of http://doc.rust-lang.org/1.0.0-beta.2/std/thread/fn.panicking.html , for example), but acts as if all currently called functions returned early. Being able topanic!()
without cluttering logs would probably also be useful.EDIT: actually, a silent version of
panic!()
would be simpler to implement and probably better overall (avoid having separate panic mechanisms, as pointed by @Diggsey)The text was updated successfully, but these errors were encountered: