Skip to content

Commit 5e58b05

Browse files
committed
Fix subprocess.call
1 parent 9d136d6 commit 5e58b05

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

vm/src/stdlib/subprocess.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl PopenRef {
148148
self.process.borrow().exit_status()
149149
}
150150

151-
fn wait(self, args: PopenWaitArgs, vm: &VirtualMachine) -> PyResult<()> {
151+
fn wait(self, args: PopenWaitArgs, vm: &VirtualMachine) -> PyResult<i64> {
152152
let timeout = match args.timeout {
153153
Some(timeout) => self
154154
.process
@@ -157,11 +157,16 @@ impl PopenRef {
157157
None => self.process.borrow_mut().wait().map(Some),
158158
}
159159
.map_err(|s| vm.new_os_error(format!("Could not start program: {}", s)))?;
160-
if timeout.is_none() {
160+
if let Some(exit) = timeout {
161+
use subprocess::ExitStatus::*;
162+
Ok(match exit {
163+
Exited(i) => i.into(),
164+
Signaled(s) => -i64::from(s),
165+
_ => unreachable!("should not occur in normal operation"),
166+
})
167+
} else {
161168
let timeout_expired = vm.try_class("_subprocess", "TimeoutExpired")?;
162169
Err(vm.new_exception_msg(timeout_expired, "Timeout".to_owned()))
163-
} else {
164-
Ok(())
165170
}
166171
}
167172

0 commit comments

Comments
 (0)