Patchwork [3,of,4] worker: propagate exit code to main process

login
register
mail settings
Submitter Yuya Nishihara
Date April 15, 2017, 10:18 a.m.
Message ID <535303fbc0cbdaa0c02a.1492251517@mimosa>
Download mbox | patch
Permalink /patch/20214/
State Accepted
Delegated to: Kevin Bullock
Headers show

Comments

Yuya Nishihara - April 15, 2017, 10:18 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1492230464 -32400
#      Sat Apr 15 13:27:44 2017 +0900
# Node ID 535303fbc0cbdaa0c02a5aec441625c6e9b7b07d
# Parent  5f5fbac079aaa4c9872c101152a2be319ae9d19b
worker: propagate exit code to main process

Follows up 86cd09bc13ba.

Patch

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -144,13 +144,15 @@  def _posixworker(ui, func, staticargs, a
                 os.close(rfd)
                 for i, item in func(*(staticargs + (pargs,))):
                     os.write(wfd, '%d %s\n' % (i, item))
+                return 0
 
             # make sure we use os._exit in all code paths. otherwise the worker
             # may do some clean-ups which could cause surprises like deadlock.
             # see sshpeer.cleanup for example.
+            ret = 0
             try:
                 try:
-                    scmutil.callcatch(ui, workerfunc)
+                    ret = scmutil.callcatch(ui, workerfunc)
                 finally:
                     ui.flush()
             except KeyboardInterrupt:
@@ -162,7 +164,7 @@  def _posixworker(ui, func, staticargs, a
                 finally:
                     os._exit(255)
             else:
-                os._exit(0)
+                os._exit(ret & 255)
         pids.add(pid)
     os.close(wfd)
     fp = os.fdopen(rfd, pycompat.sysstr('rb'), 0)
diff --git a/tests/test-worker.t b/tests/test-worker.t
--- a/tests/test-worker.t
+++ b/tests/test-worker.t
@@ -70,8 +70,9 @@  Known exception should be caught, but pr
   > test 100000.0 abort
   start
   abort: known exception
-  done
+  [255]
 
   $ hg --config "extensions.t=$abspath" --config 'worker.numcpus=2' \
   > test 100000.0 abort --traceback 2>&1 | grep '^Traceback'
   Traceback (most recent call last):
+  Traceback (most recent call last):