changeset 14104:23fc62e0a960 stable

zeroconf: notify the Zeroconf threads when hg exits Zeroconf launches two threads in the background, and they wait on Condition objects to exit. We need to call Zeroconf.close() to release those conditions so that threads can gracefully exit. This means that an interrupt on the hg process will now gracefully propagate to the Zeroconf children, fixing that bug which did not allow us to kill an `hg serve` process.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Sat, 30 Apr 2011 19:36:59 +0200
parents 2b1226693c70
children 3cb1e95676ad
files hgext/zeroconf/__init__.py
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/zeroconf/__init__.py	Fri Apr 29 22:21:13 2011 +0300
+++ b/hgext/zeroconf/__init__.py	Sat Apr 30 19:36:59 2011 +0200
@@ -27,7 +27,7 @@
 import socket, time, os
 
 import Zeroconf
-from mercurial import ui, hg, encoding, util
+from mercurial import ui, hg, encoding, util, dispatch
 from mercurial import extensions
 from mercurial.hgweb import hgweb_mod
 from mercurial.hgweb import hgwebdir_mod
@@ -166,6 +166,18 @@
             return name.encode(encoding.encoding)
     return orig(source)
 
+def cleanupafterdispatch(orig, ui, options, cmd, cmdfunc):
+    try:
+        return orig(ui, options, cmd, cmdfunc)
+    finally:
+        # we need to call close() on the server to notify() the various
+        # threading Conditions and allow the background threads to exit
+        global server
+        if server:
+            server.close()
+
+extensions.wrapfunction(dispatch, '_runcommand', cleanupafterdispatch)
+
 extensions.wrapfunction(ui.ui, 'config', config)
 extensions.wrapfunction(ui.ui, 'configitems', configitems)
 extensions.wrapfunction(hg, 'defaultdest', defaultdest)