Skip to content

Commit 34dcba4

Browse files
authored
Remove explicit __del__'s in threaded classes (#4590)
The changes in #4577 introduced a bit of flakiness on pre-3.10 due to a weird interaction of `capsys`, `stderr` logging and our object lifecycles. In this PR, I'm removing all the explicit `__del__` `kill`s since we [call them all explicitly in `client.close`](https://github.com/getsentry/sentry-python/blob/09c2e32cc7a618e49f5d8ae59e22d8b12f253687/sentry_sdk/client.py#L1001-L1021) anyway and that's already cleaner. Having logic in `__del__` causes non-deterministic GC behavior, especially with threaded code. Stacktrace is linked in a comment below where you can see the `transport.__del__` method is causing the weird `reentrant` logging bug to `stderr`.
1 parent da8332a commit 34dcba4

File tree

3 files changed

+0
-15
lines changed

3 files changed

+0
-15
lines changed

sentry_sdk/monitor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,3 @@ def downsample_factor(self):
118118
def kill(self):
119119
# type: () -> None
120120
self._running = False
121-
122-
def __del__(self):
123-
# type: () -> None
124-
self.kill()

sentry_sdk/sessions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,3 @@ def add_session(
271271
def kill(self):
272272
# type: (...) -> None
273273
self.__shutdown_requested.set()
274-
275-
def __del__(self):
276-
# type: (...) -> None
277-
self.kill()

sentry_sdk/transport.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,6 @@ def is_healthy(self):
158158
# type: (Self) -> bool
159159
return True
160160

161-
def __del__(self):
162-
# type: (Self) -> None
163-
try:
164-
self.kill()
165-
except Exception:
166-
pass
167-
168161

169162
def _parse_rate_limits(header, now=None):
170163
# type: (str, Optional[datetime]) -> Iterable[Tuple[Optional[EventDataCategory], datetime]]

0 commit comments

Comments
 (0)