[PATCH 4 of 8 V4] worker: change "pids" to a set

Jun Wu quark at fb.com
Fri Nov 11 22:11:35 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1478919718 0
#      Sat Nov 12 03:01:58 2016 +0000
# Node ID 10d4102eab371e6b6fcbfef92af6fe9457aabcc4
# Parent  15594c001edb494e4ee4faff6fc6730772271768
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 10d4102eab37
worker: change "pids" to a set

We are going to remove individual "pid" from the "pids" set in
"waitforworkers", a set is a more efficient structure for this purpose.

The fact that "set.pop()" being "atomic" at Python code level (not
interruptible by signal handlers) is also useful in a following patch.

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -86,5 +86,5 @@ def _posixworker(ui, func, staticargs, a
     oldhandler = signal.getsignal(signal.SIGINT)
     signal.signal(signal.SIGINT, signal.SIG_IGN)
-    pids, problem = [], [0]
+    pids, problem = set(), [0]
     def killworkers():
         # if one worker bails, there's no good reason to wait for the rest
@@ -116,6 +116,5 @@ def _posixworker(ui, func, staticargs, a
                 # other exceptions are allowed to propagate, we rely
                 # on lock.py's pid checks to avoid release callbacks
-        pids.append(pid)
-    pids.reverse()
+        pids.add(pid)
     os.close(wfd)
     fp = os.fdopen(rfd, 'rb', 0)


More information about the Mercurial-devel mailing list