commandserver: promote .cleanup() hook from chgserver
This allows us to unify _requesthandler.handle().
--- 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.