TracMercurial hooks.py dies when using TortoiseHg
|Reported by:||Owned by:||Christian Boos|
|Priority:||normal||Milestone:||plugin - mercurial|
Hooks pipe stdin.
In the hooks.py script it uses subprocess.Popen to call trac-admin. If you're running from the console it should be fine, but when you try to run from TortoiseHg on Windows you get a nice "helpful" message:
error: commit hook raised an exception: [Error 6] The handle is invalid
It took me a while but I finally tracked down the problem - apparently it's a more or less known issue with the subprocess module.
The fix is surprisingly simple - change this:
proc = subprocess.Popen(command, close_fds=close_fds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
proc = subprocess.Popen(command, close_fds=close_fds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
Apparently when there's no console on Windows (e.g. running Mercurial commits by way of TortoiseHg)
subprocess cannot inherit the standard handles when the process has no console, you have to create pipes for all 3 channels, and close those that are not needed. Python mailing list