Merge pull request #868 from letsencrypt/sysexit_error

ErrorHandler should ignore sys.exit
This commit is contained in:
Peter Eckersley
2015-10-02 00:59:24 -07:00
2 changed files with 13 additions and 3 deletions
+4 -3
View File
@@ -22,8 +22,8 @@ class ErrorHandler(object):
"""Registers functions to be called if an exception or signal occurs.
This class allows you to register functions that will be called when
an exception or signal is encountered. The class works best as a
context manager. For example:
an exception (excluding SystemExit) or signal is encountered. The
class works best as a context manager. For example:
with ErrorHandler(cleanup_func):
do_something()
@@ -50,7 +50,8 @@ class ErrorHandler(object):
self.set_signal_handlers()
def __exit__(self, exec_type, exec_value, trace):
if exec_value is not None:
# SystemExit is ignored to properly handle forks that don't exec
if exec_type not in (None, SystemExit):
logger.debug("Encountered exception:\n%s", "".join(
traceback.format_exception(exec_type, exec_value, trace)))
self.call_registered()
+9
View File
@@ -1,5 +1,6 @@
"""Tests for letsencrypt.error_handler."""
import signal
import sys
import unittest
import mock
@@ -50,6 +51,14 @@ class ErrorHandlerTest(unittest.TestCase):
self.init_func.assert_called_once_with()
bad_func.assert_called_once_with()
def test_sysexit_ignored(self):
try:
with self.handler:
sys.exit(0)
except SystemExit:
pass
self.assertFalse(self.init_func.called)
if __name__ == "__main__":
unittest.main() # pragma: no cover