diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -474,11 +474,13 @@ def chunkselector(ui, headerlist, operat
     ui.write(_('starting interactive selection\n'))
     chunkselector = curseschunkselector(headerlist, ui, operation)
     f = signal.getsignal(signal.SIGTSTP)
-    curses.wrapper(chunkselector.main)
-    if chunkselector.initerr is not None:
-        raise error.Abort(chunkselector.initerr)
-    # ncurses does not restore signal handler for SIGTSTP
-    signal.signal(signal.SIGTSTP, f)
+    try:
+        curses.wrapper(chunkselector.main)
+        if chunkselector.initerr is not None:
+            raise error.Abort(chunkselector.initerr)
+        # ncurses does not restore signal handler for SIGTSTP
+    finally:
+        signal.signal(signal.SIGTSTP, f)
     return chunkselector.opts
 
 def testdecorator(testfn, f):