Patchwork [3,of,9,v2] atexit: switch to home-grown implementation

login
register
mail settings
Submitter Bryan O'Sullivan
Date April 14, 2017, 4:29 a.m.
Message ID <c9e44f83b04ad8179789.1492144181@jsdf-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/20185/
State Accepted
Headers show

Comments

Bryan O'Sullivan - April 14, 2017, 4:29 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1491947652 25200
#      Tue Apr 11 14:54:12 2017 -0700
# Node ID c9e44f83b04ad81797891ba63b0fa4d1587880ea
# Parent  b35bc05e7a695ed8cdfd809070965ef9ea9266f9
atexit: switch to home-grown implementation

Patch

diff --git a/contrib/memory.py b/contrib/memory.py
--- a/contrib/memory.py
+++ b/contrib/memory.py
@@ -12,7 +12,6 @@  prints it to ``stderr`` on exit.
 '''
 
 from __future__ import absolute_import
-import atexit
 
 def memusage(ui):
     """Report memory usage of the current process."""
@@ -29,4 +28,4 @@  def memusage(ui):
                             for k, v in result.iteritems()]) + "\n")
 
 def extsetup(ui):
-    atexit.register(memusage, ui)
+    ui.atexit(memusage, ui)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -7,7 +7,6 @@ 
 
 from __future__ import absolute_import, print_function
 
-import atexit
 import difflib
 import errno
 import getopt
@@ -767,7 +766,7 @@  def _dispatch(req):
                 ui.warn(
                     _("time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
                     (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
-            atexit.register(print_time)
+            ui.atexit(print_time)
 
         if options['verbose'] or options['debug'] or options['quiet']:
             for opt in ('verbose', 'debug', 'quiet'):
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -7,7 +7,6 @@ 
 
 from __future__ import absolute_import
 
-import atexit
 import collections
 import contextlib
 import errno
@@ -931,7 +930,7 @@  class ui(object):
         if self._isatty(util.stderr):
             os.dup2(pager.stdin.fileno(), util.stderr.fileno())
 
-        @atexit.register
+        @self.atexit
         def killpager():
             if util.safehasattr(signal, "SIGINT"):
                 signal.signal(signal.SIGINT, signal.SIG_IGN)