Skip to content

Commit ba3d544

Browse files
committed
do not rely on os.WIFSIGNALED and os.WIFEXITED in popen.poll()
1 parent 9a810ea commit ba3d544

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MultiprocessingModuleBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ PTuple waittid(long id, @SuppressWarnings("unused") int options) {
225225
// TODO implement for options - WNOHANG and 0
226226
Thread thread = lang.getChildContextThread(tid);
227227
if (thread != null && thread.isAlive()) {
228-
return factory().createTuple(new Object[]{0, 0});
228+
return factory().createTuple(new Object[]{0, 0, 0});
229229
}
230230

231231
PythonContext.ChildContextData data = lang.getChildContextData(tid);
232-
return factory().createTuple(new Object[]{id, data != null ? data.getExitCode() : 0});
232+
return factory().createTuple(new Object[]{id, data.wasSignaled() ? data.getExitCode() : 0, data.getExitCode()});
233233
}
234234
}
235235

@@ -248,7 +248,7 @@ Object terminate(long id, PInt sig) {
248248
TruffleContext truffleCtx = data.getTruffleContext();
249249
if (!truffleCtx.isCancelling() && data.compareAndSetExiting(false, true)) {
250250
LOGGER.fine("terminating spawned thread");
251-
data.setExitCode(sig.intValue());
251+
data.setSignaled(sig.intValue());
252252
truffleCtx.closeCancelled(this, "_terminate_spawned_thread");
253253
}
254254
} catch (InterruptedException ex) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ public Thread getOwner() {
473473

474474
public static final class ChildContextData {
475475
private int exitCode = 0;
476+
private boolean signaled;
476477
@CompilationFinal private TruffleContext ctx;
477478
@CompilationFinal private PythonContext parentCtx;
478479

@@ -487,6 +488,15 @@ public int getExitCode() {
487488
return this.exitCode;
488489
}
489490

491+
public void setSignaled(int signaledCode) {
492+
this.signaled = true;
493+
this.exitCode = signaledCode;
494+
}
495+
496+
public boolean wasSignaled() {
497+
return this.signaled;
498+
}
499+
490500
private void setTruffleContext(TruffleContext ctx) {
491501
assert this.ctx == null;
492502
this.ctx = ctx;

graalpython/lib-python/3/multiprocessing/popen_truffleprocess.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ def duplicate_for_child(self, fd):
4545
def poll(self, flag=os.WNOHANG):
4646
if self.returncode is None:
4747
try:
48-
tid, sts = _waittid(self._tid, flag)
48+
# this is different than in popen_fork -> os.waitpid(self.pid, flag)
49+
# we have no real proces pid and a process
50+
# which could have been evenutally signaled
51+
tid, sigcode, exitcode = _waittid(self._tid, flag)
4952
except OSError as e:
5053
return None
51-
if tid == self._tid:
52-
if os.WIFSIGNALED(sts):
53-
self.returncode = -os.WTERMSIG(sts)
54+
if tid == self._tid:
55+
if sigcode > 0:
56+
self.returncode = -sigcode
5457
else:
55-
assert os.WIFEXITED(sts), "Status is {:n}".format(sts)
56-
self.returncode = os.WEXITSTATUS(sts)
58+
self.returncode = exitcode
5759
return self.returncode
5860

5961
def wait(self, timeout=None):

0 commit comments

Comments
 (0)