Add non-global ways to set debug and pipefail modes #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this is the second of two patches aimed at addressing thread safety issues. set_debug() and set_pipefail() change the debug and pipefail settings globally, which makes it impossible to reliably run commands with different settings in different threads. in single-threaded programs, this doesn’t really matter, so they are certainly still useful.
this patch adds ScopedDebug and ScopedPipefail, which override the global debug and pipefail settings, in the current thread only, until they go out of scope. calling
set(new_value)
changes the setting toSome(new_value)
, giving you aSelf(old_value)
that when dropped, restores the value toold_value
.i’ve also split the ignore and pipefail tests into their own test function test_ignore_and_pipefail(), using ScopedPipefail so they can run in parallel with the other tests in test_pipe().