time consuming hooks: separate thread?
Chad Dombrova
chadrik at gmail.com
Sat May 1 21:32:37 UTC 2010
i come to you all looking for sage advice.
where i work all of the developers work off a network mount. everyone's repo is setup with a commit hook that updates a special repo with any changes made to a certain branch. the problem is that this update process is sometimes very time consuming and since it's running in the same thread as the commit hook it causes us to all have to wait on each commit.
so i'm weighing my options. we could have the hook open a subprocess on a separate thread to perform the update, but i'm not sure what's the best way of handling any errors that may occur. can the ui object be configured to write to a centrally stored log? or maybe use the threading module to send something back to the user? any ideas?
in sniffing around for a solution, i saw this code in tortoisehg.util.hglib:
def hgcmd_toq(q, label, args):
'''
Run an hg command in a background thread, pipe all output to a Queue
object. Assumes command is completely noninteractive.
'''
class Qui(ui.ui):
def __init__(self, src=None):
super(Qui, self).__init__(src)
self.setconfig('ui', 'interactive', 'off')
def write(self, *args, **opts):
if self._buffers:
self._buffers[-1].extend([str(a) for a in args])
else:
for a in args:
if label:
q.put((str(a), opts.get('label', '')))
else:
q.put(str(a))
def plain(self):
return True
u = Qui()
oldterm = os.environ.get('TERM')
os.environ['TERM'] = 'dumb'
ret = dispatch._dispatch(u, list(args))
if oldterm:
os.environ['TERM'] = oldterm
return ret
i don't understand what the purpose of the Qui object is. where is it writing to? i'm also not clear on how this is getting sent to a background thread, since AFAIK mercurial._dispatch runs on the current thread.
-chad
More information about the Mercurial
mailing list