@@ -142,12 +142,14 @@ def _supports_lane_synchronization(queue) -> bool:
142142
143143
144144def _new_lane_queue (maxsize : int ) -> Queue :
145- """Return a safe queue, disabling async capture instead of raising on failure."""
145+ """Return a safe queue, disabling the lane instead of raising on failure."""
146146 log = logging .getLogger ("posthog" )
147147 try :
148148 queue : Queue = Queue (maxsize )
149149 except Exception :
150- log .exception ("Failed to initialize queue.Queue; disabling the PostHog client" )
150+ log .exception (
151+ "Failed to initialize queue.Queue; disabling asynchronous capture for the lane"
152+ )
151153 return cast (Queue , _DisabledLaneQueue (maxsize ))
152154
153155 if _supports_lane_synchronization (queue ):
@@ -157,15 +159,16 @@ def _new_lane_queue(maxsize: int) -> Queue:
157159 if monkey is None :
158160 log .error (
159161 "queue.Queue lacks the synchronization interface required by PostHog "
160- "and gevent.monkey is not loaded; disabling the PostHog client "
162+ "and gevent.monkey is not loaded; disabling asynchronous capture for the lane "
161163 )
162164 return cast (Queue , _DisabledLaneQueue (maxsize ))
163165
164166 try :
165167 if not monkey .is_object_patched ("queue" , "Queue" ):
166168 log .error (
167169 "queue.Queue lacks the synchronization interface required by PostHog "
168- "but gevent does not report it as patched; disabling the PostHog client"
170+ "but gevent does not report it as patched; disabling asynchronous "
171+ "capture for the lane"
169172 )
170173 return cast (Queue , _DisabledLaneQueue (maxsize ))
171174
@@ -174,7 +177,7 @@ def _new_lane_queue(maxsize: int) -> Queue:
174177 except Exception :
175178 log .exception (
176179 "Failed to restore the original queue.Queue after gevent monkey-patching; "
177- "disabling the PostHog client "
180+ "disabling asynchronous capture for the lane "
178181 )
179182 return cast (Queue , _DisabledLaneQueue (maxsize ))
180183
@@ -183,7 +186,7 @@ def _new_lane_queue(maxsize: int) -> Queue:
183186
184187 log .error (
185188 "The queue.Queue restored after gevent monkey-patching lacks the synchronization "
186- "interface required by PostHog; disabling the PostHog client "
189+ "interface required by PostHog; disabling asynchronous capture for the lane "
187190 )
188191 return cast (Queue , _DisabledLaneQueue (maxsize ))
189192
@@ -403,7 +406,7 @@ def __init__(
403406 self .start ()
404407
405408 def _start_locked (self ) -> None :
406- if self ._started or self ._closed :
409+ if self ._started or self ._closed or not self . available :
407410 return
408411 for _ in range (self ._thread_count ):
409412 consumer = Consumer (
@@ -441,7 +444,7 @@ def start(self):
441444 def enqueue (self , msg ) -> bool :
442445 """Atomically admit and queue `msg`, starting the lane on its first event."""
443446 with self ._start_lock :
444- if self ._closed :
447+ if self ._closed or not self . available :
445448 return False
446449 self ._start_locked ()
447450 try :
@@ -1036,8 +1039,6 @@ def __init__(
10361039 eager_start = False ,
10371040 )
10381041 self ._lanes = [self ._analytics_lane , self ._ai_lane ]
1039- if not all (lane .available for lane in self ._lanes ):
1040- self .disabled = True
10411042
10421043 if hasattr (os , "register_at_fork" ):
10431044 weak_self = weakref .ref (self )
@@ -2137,8 +2138,6 @@ def _reinit_after_fork(self):
21372138 )
21382139 for lane in self ._lanes :
21392140 lane .rebuild_after_fork (closed = terminal_requested )
2140- if not all (lane .available for lane in self ._lanes ):
2141- self .disabled = True
21422141
21432142 self ._lifecycle_lock = threading .Lock ()
21442143 self ._lifecycle_condition = threading .Condition (self ._lifecycle_lock )
@@ -2319,7 +2318,14 @@ def send_sync() -> None:
23192318 self .log .debug ("enqueued %s." , msg ["event" ])
23202319 return sent_uuid
23212320
2322- if lane ._closed :
2321+ if not lane .available :
2322+ self .log .warning (
2323+ "%s lane is unavailable because a compatible queue could not be "
2324+ "initialized, dropping event %s" ,
2325+ lane .name ,
2326+ msg ["event" ],
2327+ )
2328+ elif lane ._closed :
23232329 self .log .warning (
23242330 "%s lane received event %s after shutdown, dropping it" ,
23252331 lane .name ,
0 commit comments