comparison mercurial/worker.py @ 38536:8c38d2948217

worker: support more return types in posix worker This allows us to return things that aren't tuple(int, str) from worker functions. I wanted to use marshal instead of pickle, but it seems to read from the pipe in non-blocking mode, which means it stops before it sees the results. The windows worker already supports arbitrary return values without serialization, because it uses threads instead of subprocesses. Differential Revision: https://phab.mercurial-scm.org/D3845
author Danny Hooper <hooper@google.com>
date Tue, 26 Jun 2018 15:27:29 -0700
parents 8fb9985382be
children 9e6afe7fca31
comparison
equal deleted inserted replaced
38535:b86664c81833 38536:8c38d2948217
153 signal.signal(signal.SIGINT, oldhandler) 153 signal.signal(signal.SIGINT, oldhandler)
154 signal.signal(signal.SIGCHLD, oldchldhandler) 154 signal.signal(signal.SIGCHLD, oldchldhandler)
155 155
156 def workerfunc(): 156 def workerfunc():
157 os.close(rfd) 157 os.close(rfd)
158 for i, item in func(*(staticargs + (pargs,))): 158 for result in func(*(staticargs + (pargs,))):
159 os.write(wfd, '%d %s\n' % (i, item)) 159 os.write(wfd, util.pickle.dumps(result))
160 return 0 160 return 0
161 161
162 ret = scmutil.callcatch(ui, workerfunc) 162 ret = scmutil.callcatch(ui, workerfunc)
163 except: # parent re-raises, child never returns 163 except: # parent re-raises, child never returns
164 if os.getpid() == parentpid: 164 if os.getpid() == parentpid:
185 if status: 185 if status:
186 if status < 0: 186 if status < 0:
187 os.kill(os.getpid(), -status) 187 os.kill(os.getpid(), -status)
188 sys.exit(status) 188 sys.exit(status)
189 try: 189 try:
190 for line in util.iterfile(fp): 190 while True:
191 l = line.split(' ', 1) 191 try:
192 yield int(l[0]), l[1][:-1] 192 yield util.pickle.load(fp)
193 except EOFError:
194 break
195 except IOError as e:
196 if e.errno == errno.EINTR:
197 continue
198 raise
193 except: # re-raises 199 except: # re-raises
194 killworkers() 200 killworkers()
195 cleanup() 201 cleanup()
196 raise 202 raise
197 cleanup() 203 cleanup()