commandserver: promote .cleanup() hook from chgserver
authorYuya Nishihara <yuya@tcha.org>
Sat, 21 May 2016 15:18:23 +0900
changeset 29512 538d0003c9e0
parent 29511 540c01a18bb7
child 29513 e5b4d79a9140
commandserver: promote .cleanup() hook from chgserver This allows us to unify _requesthandler.handle().
hgext/chgserver.py
mercurial/commandserver.py
--- a/hgext/chgserver.py	Sat May 21 15:12:19 2016 +0900
+++ b/hgext/chgserver.py	Sat May 21 15:18:23 2016 +0900
@@ -353,6 +353,7 @@
             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()
--- a/mercurial/commandserver.py	Sat May 21 15:12:19 2016 +0900
+++ b/mercurial/commandserver.py	Sat May 21 15:18:23 2016 +0900
@@ -179,6 +179,10 @@
 
         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 @@
             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 @@
                     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.