File tree 2 files changed +21
-8
lines changed
2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -332,18 +332,27 @@ def __init__(
332
332
self ._ensure_thread ()
333
333
334
334
def _ensure_thread (self ):
335
- # type: (...) -> None
335
+ # type: (...) -> bool
336
336
"""For forking processes we might need to restart this thread.
337
337
This ensures that our process actually has that thread running.
338
338
"""
339
+ if not self ._running :
340
+ return False
339
341
pid = os .getpid ()
340
342
if self ._flusher_pid == pid :
341
- return
343
+ return True
342
344
with self ._lock :
343
345
self ._flusher_pid = pid
344
346
self ._flusher = Thread (target = self ._flush_loop )
345
347
self ._flusher .daemon = True
346
- self ._flusher .start ()
348
+ try :
349
+ self ._flusher .start ()
350
+ except RuntimeError :
351
+ # Unfortunately at this point the interpreter is in a start that no
352
+ # longer allows us to spawn a thread and we have to bail.
353
+ self ._running = False
354
+ return False
355
+ return True
347
356
348
357
def _flush_loop (self ):
349
358
# type: (...) -> None
@@ -400,9 +409,7 @@ def add(
400
409
timestamp = None , # type: Optional[float]
401
410
):
402
411
# type: (...) -> None
403
- self ._ensure_thread ()
404
-
405
- if self ._flusher is None :
412
+ if not self ._ensure_thread () or self ._flusher is None :
406
413
return
407
414
408
415
if timestamp is None :
Original file line number Diff line number Diff line change @@ -67,8 +67,14 @@ def start(self):
67
67
target = self ._target , name = "raven-sentry.BackgroundWorker"
68
68
)
69
69
self ._thread .daemon = True
70
- self ._thread .start ()
71
- self ._thread_for_pid = os .getpid ()
70
+ try :
71
+ self ._thread .start ()
72
+ self ._thread_for_pid = os .getpid ()
73
+ except RuntimeError :
74
+ # At this point we can no longer start because the interpreter
75
+ # is already shutting down. Sadly at this point we can no longer
76
+ # send out events.
77
+ self ._thread = None
72
78
73
79
def kill (self ):
74
80
# type: () -> None
You can’t perform that action at this time.
0 commit comments