mercurial/ui.py
changeset 31956 c13ff31818b0
parent 31954 e518192d6bac
child 31958 de5c9d0e02ea
--- a/mercurial/ui.py	Fri Apr 14 08:55:18 2017 +0200
+++ b/mercurial/ui.py	Tue Apr 11 14:54:12 2017 -0700
@@ -139,6 +139,8 @@
         """
         # _buffers: used for temporary capture of output
         self._buffers = []
+        # _exithandlers: callbacks run at the end of a request
+        self._exithandlers = []
         # 3-tuple describing how each buffer in the stack behaves.
         # Values are (capture stderr, capture subprocesses, apply labels).
         self._bufferstates = []
@@ -163,6 +165,7 @@
         self._styles = {}
 
         if src:
+            self._exithandlers = src._exithandlers
             self.fout = src.fout
             self.ferr = src.ferr
             self.fin = src.fin
@@ -946,6 +949,13 @@
 
         return True
 
+    def atexit(self, func, *args, **kwargs):
+        '''register a function to run after dispatching a request
+
+        Handlers do not stay registered across request boundaries.'''
+        self._exithandlers.append((func, args, kwargs))
+        return func
+
     def interface(self, feature):
         """what interface to use for interactive console features?