Show More
@@ -59,6 +59,23 b' class request(object):' | |||||
59 | self.fout = fout |
|
59 | self.fout = fout | |
60 | self.ferr = ferr |
|
60 | self.ferr = ferr | |
61 |
|
61 | |||
|
62 | def _runexithandlers(self): | |||
|
63 | exc = None | |||
|
64 | handlers = self.ui._exithandlers | |||
|
65 | try: | |||
|
66 | while handlers: | |||
|
67 | func, args, kwargs = handlers.pop() | |||
|
68 | try: | |||
|
69 | func(*args, **kwargs) | |||
|
70 | except: # re-raises below | |||
|
71 | if exc is None: | |||
|
72 | exc = sys.exc_info()[1] | |||
|
73 | self.ui.warn(('error in exit handlers:\n')) | |||
|
74 | self.ui.traceback(force=True) | |||
|
75 | finally: | |||
|
76 | if exc is not None: | |||
|
77 | raise exc | |||
|
78 | ||||
62 | def run(): |
|
79 | def run(): | |
63 | "run the command in sys.argv" |
|
80 | "run the command in sys.argv" | |
64 | sys.exit((dispatch(request(pycompat.sysargv[1:])) or 0) & 255) |
|
81 | sys.exit((dispatch(request(pycompat.sysargv[1:])) or 0) & 255) | |
@@ -146,6 +163,10 b' def dispatch(req):' | |||||
146 | req.ui.log('uiblocked', 'ui blocked ms', **req.ui._blockedtimes) |
|
163 | req.ui.log('uiblocked', 'ui blocked ms', **req.ui._blockedtimes) | |
147 | req.ui.log("commandfinish", "%s exited %s after %0.2f seconds\n", |
|
164 | req.ui.log("commandfinish", "%s exited %s after %0.2f seconds\n", | |
148 | msg, ret or 0, duration) |
|
165 | msg, ret or 0, duration) | |
|
166 | try: | |||
|
167 | req._runexithandlers() | |||
|
168 | except: # exiting, so no re-raises | |||
|
169 | ret = ret or -1 | |||
149 | return ret |
|
170 | return ret | |
150 |
|
171 | |||
151 | def _runcatch(req): |
|
172 | def _runcatch(req): |
@@ -139,6 +139,8 b' class ui(object):' | |||||
139 | """ |
|
139 | """ | |
140 | # _buffers: used for temporary capture of output |
|
140 | # _buffers: used for temporary capture of output | |
141 | self._buffers = [] |
|
141 | self._buffers = [] | |
|
142 | # _exithandlers: callbacks run at the end of a request | |||
|
143 | self._exithandlers = [] | |||
142 | # 3-tuple describing how each buffer in the stack behaves. |
|
144 | # 3-tuple describing how each buffer in the stack behaves. | |
143 | # Values are (capture stderr, capture subprocesses, apply labels). |
|
145 | # Values are (capture stderr, capture subprocesses, apply labels). | |
144 | self._bufferstates = [] |
|
146 | self._bufferstates = [] | |
@@ -163,6 +165,7 b' class ui(object):' | |||||
163 | self._styles = {} |
|
165 | self._styles = {} | |
164 |
|
166 | |||
165 | if src: |
|
167 | if src: | |
|
168 | self._exithandlers = src._exithandlers | |||
166 | self.fout = src.fout |
|
169 | self.fout = src.fout | |
167 | self.ferr = src.ferr |
|
170 | self.ferr = src.ferr | |
168 | self.fin = src.fin |
|
171 | self.fin = src.fin | |
@@ -946,6 +949,13 b' class ui(object):' | |||||
946 |
|
949 | |||
947 | return True |
|
950 | return True | |
948 |
|
951 | |||
|
952 | def atexit(self, func, *args, **kwargs): | |||
|
953 | '''register a function to run after dispatching a request | |||
|
954 | ||||
|
955 | Handlers do not stay registered across request boundaries.''' | |||
|
956 | self._exithandlers.append((func, args, kwargs)) | |||
|
957 | return func | |||
|
958 | ||||
949 | def interface(self, feature): |
|
959 | def interface(self, feature): | |
950 | """what interface to use for interactive console features? |
|
960 | """what interface to use for interactive console features? | |
951 |
|
961 |
General Comments 0
You need to be logged in to leave comments.
Login now