-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚸 Ensure exception propagation from threads via
std::async
(#263)
## Description If an unhandled exception occurs in a C++ thread, `std::terminate` is called. This is undesirable, especially from the Python side, since there is no way for the exception to be propagated to Python and, thus, for handling it gracefully. It just causes a crash of the Python executable. Fortunately, C++ offers some ways to allow for exceptions from threads to be propagated to the main thread. This is done by using `std::async` instead of `std::thread`. Upon creation, it returns an `std::future` object that is used to refer to the return value of the asynchronous computation. A future can hold the return value, but also an exception. Upon calling `future.get()`, either the value is returned or the stored exception is rethrown. In this way, any exception happening concurrently is eventually propagated to the main thread and, as a result, to Python. This also caught some instances of methods being declared `noexcept` despite possibly throwing. This also causes the C++ runtime to call `std::terminate` instead of resulting in a proper error message. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style guidelines.
- Loading branch information
Showing
7 changed files
with
125 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters