# HG changeset patch # User Danny Hooper # Date 1530052049 25200 # Node ID 8c38d29482177cd40243a008057d6762c7d23c6f # Parent b86664c81833a48a24dd011a6fff141c8e49a040 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 diff -r b86664c81833 -r 8c38d2948217 mercurial/worker.py --- a/mercurial/worker.py Tue Jun 19 19:18:31 2018 +0100 +++ b/mercurial/worker.py Tue Jun 26 15:27:29 2018 -0700 @@ -155,8 +155,8 @@ def workerfunc(): os.close(rfd) - for i, item in func(*(staticargs + (pargs,))): - os.write(wfd, '%d %s\n' % (i, item)) + for result in func(*(staticargs + (pargs,))): + os.write(wfd, util.pickle.dumps(result)) return 0 ret = scmutil.callcatch(ui, workerfunc) @@ -187,9 +187,15 @@ os.kill(os.getpid(), -status) sys.exit(status) try: - for line in util.iterfile(fp): - l = line.split(' ', 1) - yield int(l[0]), l[1][:-1] + while True: + try: + yield util.pickle.load(fp) + except EOFError: + break + except IOError as e: + if e.errno == errno.EINTR: + continue + raise except: # re-raises killworkers() cleanup()