---
title: "sys.exit"
description: "Learn how to use Sentry to capture sys.exit calls."
url: https://docs.sentry.io/platforms/python/integrations/sys_exit/
---

# sys.exit | Sentry for Python

The `SysExitIntegration` records `sys.exit` calls by capturing the `SystemExit` exception raised by `sys.exit`.

## [Install](https://docs.sentry.io/platforms/python/integrations/sys_exit.md#install)

```bash
pip install "sentry-sdk"
```

## [Configure](https://docs.sentry.io/platforms/python/integrations/sys_exit.md#configure)

The `SysExitIntegration` is disabled by default, and the SDK only captures `SystemExit` exceptions automatically if this integration is manually enabled.

A `sys.exit` call is considered "successful" when the function is passed a value of `0` or `None`. Passing any other value results in an "unsuccessful" exit.

To enable the `SysExitIntegration` and configure it to only capture unsuccessful `sys.exit` calls, use the following:

```python
import sentry_sdk
from sentry_sdk.integrations.sys_exit import SysExitIntegration

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    integrations=[SysExitIntegration()],
)
```

If you wish to capture successful and unsuccessful `sys.exit` calls, use the following, instead:

```python
import sentry_sdk
from sentry_sdk.integrations.sys_exit import SysExitIntegration

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    integrations=[SysExitIntegration(capture_successful_exits=True)],
)
```

## [Verify](https://docs.sentry.io/platforms/python/integrations/sys_exit.md#verify)

Running the following snippet should result in a `SystemExit` exception being reported to Sentry.

```python
import sys

import sentry_sdk
from sentry_sdk.integrations.sys_exit import SysExitIntegration

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    integrations=[SysExitIntegration()],
)

sys.exit(1)
```

If you use `capture_successful_exits=True`, calling `sys.exit(0)` should also report a `SystemExit` exception to Sentry.

##### Manually-raised SystemExit

Please note that the `SysExitIntegration` only captures `SystemExit` exceptions which are raised by calling `sys.exit`. If your code raises `SystemExit` without calling `sys.exit`, the exception will not be reported to Sentry.
