From patchwork Thu Jun 30 14:26:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,3] commandserver: promote .cleanup() hook from chgserver From: Yuya Nishihara X-Patchwork-Id: 15678 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Thu, 30 Jun 2016 23:26:54 +0900 # HG changeset patch # User Yuya Nishihara # Date 1463811503 -32400 # Sat May 21 15:18:23 2016 +0900 # Node ID b00830fdf008c83d361b05491b023778275dfd61 # Parent ced2dca6ea44867d8b02d6026d38fa099c30c6c1 commandserver: promote .cleanup() hook from chgserver This allows us to unify _requesthandler.handle(). diff --git a/hgext/chgserver.py b/hgext/chgserver.py --- a/hgext/chgserver.py +++ b/hgext/chgserver.py @@ -349,6 +349,7 @@ class chgcmdserver(commandserver.server) self.capabilities['validate'] = chgcmdserver.validate def cleanup(self): + super(chgcmdserver, self).cleanup() # dispatch._runcatch() does not flush outputs if exception is not # handled by dispatch._dispatch() self.ui.flush() diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py --- a/mercurial/commandserver.py +++ b/mercurial/commandserver.py @@ -179,6 +179,10 @@ class server(object): self.client = fin + def cleanup(self): + """release and restore resources taken during server session""" + pass + def _read(self, size): if not size: return '' @@ -329,6 +333,7 @@ class pipeservice(object): sv = server(ui, self.repo, fin, fout) return sv.serve() finally: + sv.cleanup() _restoreio(ui, fin, fout) class _requesthandler(socketserver.StreamRequestHandler): @@ -348,6 +353,8 @@ class _requesthandler(socketserver.Strea raise except KeyboardInterrupt: pass + finally: + sv.cleanup() except: # re-raises # also write traceback to error channel. otherwise client cannot # see it because it is written to server's stderr by default.