diff --git a/hg b/hg --- a/hg +++ b/hg @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # mercurial - scalable distributed SCM # diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py --- a/mercurial/utils/procutil.py +++ b/mercurial/utils/procutil.py @@ -16,6 +16,7 @@ import signal import subprocess import sys +import threading import time from ..i18n import _ @@ -604,6 +605,14 @@ pid = os.fork() if pid: if not ensurestart: + # Even though we're not waiting on the child process, + # we still must call waitpid() on it at some point so + # it's not a zombie/defunct. This is especially relevant for + # chg since the parent process won't die anytime soon. + # We use a thread to make the overhead tiny. + def _do_wait(): + os.waitpid(pid, 0) + threading.Thread(target=_do_wait, daemon=True).start() return # Parent process (_pid, status) = os.waitpid(pid, 0)