comparison mercurial/worker.py @ 32042:8f8ad0139b8b

worker: propagate exit code to main process Follows up 86cd09bc13ba.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Apr 2017 13:27:44 +0900
parents 9d3d56aa1a9f
children b844d0d367e2
comparison
equal deleted inserted replaced
32041:38963a53ab0d 32042:8f8ad0139b8b
142 142
143 def workerfunc(): 143 def workerfunc():
144 os.close(rfd) 144 os.close(rfd)
145 for i, item in func(*(staticargs + (pargs,))): 145 for i, item in func(*(staticargs + (pargs,))):
146 os.write(wfd, '%d %s\n' % (i, item)) 146 os.write(wfd, '%d %s\n' % (i, item))
147 return 0
147 148
148 # make sure we use os._exit in all code paths. otherwise the worker 149 # make sure we use os._exit in all code paths. otherwise the worker
149 # may do some clean-ups which could cause surprises like deadlock. 150 # may do some clean-ups which could cause surprises like deadlock.
150 # see sshpeer.cleanup for example. 151 # see sshpeer.cleanup for example.
152 ret = 0
151 try: 153 try:
152 try: 154 try:
153 scmutil.callcatch(ui, workerfunc) 155 ret = scmutil.callcatch(ui, workerfunc)
154 finally: 156 finally:
155 ui.flush() 157 ui.flush()
156 except KeyboardInterrupt: 158 except KeyboardInterrupt:
157 os._exit(255) 159 os._exit(255)
158 except: # never return, therefore no re-raises 160 except: # never return, therefore no re-raises
160 ui.traceback() 162 ui.traceback()
161 ui.flush() 163 ui.flush()
162 finally: 164 finally:
163 os._exit(255) 165 os._exit(255)
164 else: 166 else:
165 os._exit(0) 167 os._exit(ret & 255)
166 pids.add(pid) 168 pids.add(pid)
167 os.close(wfd) 169 os.close(wfd)
168 fp = os.fdopen(rfd, pycompat.sysstr('rb'), 0) 170 fp = os.fdopen(rfd, pycompat.sysstr('rb'), 0)
169 def cleanup(): 171 def cleanup():
170 signal.signal(signal.SIGINT, oldhandler) 172 signal.signal(signal.SIGINT, oldhandler)