# HG changeset patch # User Marcos Chaves # Date 2007-06-21 19:58:18 # Node ID 272c0a09b2032046de3671eada475e1eace2b772 # Parent 7a7d4937272baf90af6f00bc47807a9172279583 Handle CTRL+C in serve under Windows. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2401,6 +2401,7 @@ def serve(ui, repo, **opts): class service: def init(self): + util.set_signal_handler() try: self.httpd = hgweb.server.create_server(parentui, repo) except socket.error, inst: diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1100,6 +1100,9 @@ else: return p_name return default + def set_signal_handler(): + pass + def find_exe(name, default=None): '''find path of an executable. if name contains a path component, return it as is. otherwise, diff --git a/mercurial/util_win32.py b/mercurial/util_win32.py --- a/mercurial/util_win32.py +++ b/mercurial/util_win32.py @@ -299,3 +299,12 @@ class posixfile_nt(object): raise WinIOError(err) getuser_fallback = win32api.GetUserName + +def set_signal_handler(): + """Register a termination handler for console events including + CTRL+C. python signal handlers do not work well with socket + operations. + """ + def handler(event): + win32process.ExitProcess(1) + win32api.SetConsoleCtrlHandler(handler)