diff --git a/CHANGES b/CHANGES index 73e190e96..0135267fa 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Version 6.0.0 * Refactored transports to support multiple URLs. This might affect you if you have custom subclasses of those. The main change is that the URL parameter moved from the constructor into the `send` method. +* Do not record from the sys except hook if stdin is a terminal. Version 5.32.0 -------------- diff --git a/raven/base.py b/raven/base.py index 2f147cffe..b80dd9794 100644 --- a/raven/base.py +++ b/raven/base.py @@ -242,14 +242,22 @@ def set_dsn(self, dsn=None, transport=None): self.logger.debug("Configuring Raven for host: {0}".format(self.remote)) - def install_sys_hook(self): + def install_sys_hook(self, skip_for_tty=True): global __excepthook__ if __excepthook__ is None: __excepthook__ = sys.excepthook def handle_exception(*exc_info): - self.captureException(exc_info=exc_info, level='fatal') + if not skip_for_tty: + capture = True + else: + try: + capture = not sys.stdin.isatty() + except Exception: + capture = True + if capture: + self.captureException(exc_info=exc_info, level='fatal') __excepthook__(*exc_info) handle_exception.raven_client = self sys.excepthook = handle_exception diff --git a/tests/base/tests.py b/tests/base/tests.py index 1ef4402fa..f2e54858b 100644 --- a/tests/base/tests.py +++ b/tests/base/tests.py @@ -585,3 +585,26 @@ def test_no_sys_argv(self): Client() finally: sys.argv = argv + + def test_sys_hook(self): + client = TempStoreClient(install_sys_hook=True) + try: + 1 / 0 + except Exception: + sys.excepthook(*sys.exc_info()) + + event = client.events.pop(0) + exc = event['exception']['values'][-1] + assert exc['type'] == 'ZeroDivisionError' + assert not client.events + + sys.stdin.isatty = lambda: True + try: + try: + 1 / 0 + except Exception: + sys.excepthook(*sys.exc_info()) + + assert not client.events + finally: + del sys.stdin.isatty