Fixed populating the return code for interrupted process. #5380
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.
Motivation
There is annoying behavior when you run command in the loop and can't interrupt e.g. this report and #5304. After diving into this I see the issue around return code.
The essence
Basically
p = subprocess.Popen()
populatesp.returncode
afterp.wait()
,p.poll()
orp.communicate()
(doc). But if you're usingos.waitpid()
BEFORE these functions you're capturing return code from a signal subsystem andp.returncode
will be0
like success but it's not success. So afteros.waitid
call you need to set return code manuallyp.returncode = -os.WTERMSIG(status)
like in Popen. Example:See also: Helpful things for knight.
Before
After
Notes
xonsh.jobs
. It's pretty uncomfortable work with module.procs/specs.py
#5424captured
variable looks like "just the way of capturing (stdout, object)" but in fact it affects all logic very much. We need to create table where we can see the logic difference for every type of capturing. E.g. incaptured=stdout
mode we usexonsh.jobs
to monitor the command but incaptured=object
we avoid this and some logic fromxonsh.jobs
applied instdout
mode but missed inobject
mode. We need clear map.For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 comment