@@ -31,17 +31,61 @@ def _use_process_worker(self: QueryMixinHost, provider: Any) -> bool:
3131 def _get_process_worker_client (self : QueryMixinHost ) -> Any | None :
3232 client = getattr (self , "_process_worker_client" , None )
3333 if client is not None :
34+ try :
35+ from sqlit .shared .core .debug_events import emit_debug_event
36+
37+ emit_debug_event (
38+ "process_worker.use" ,
39+ category = "process_worker" ,
40+ cached = True ,
41+ path = "sync" ,
42+ )
43+ except Exception :
44+ pass
3445 self ._touch_process_worker ()
3546 return client
47+ start = None
3648 try :
3749 from sqlit .domains .process_worker .app .process_worker_client import ProcessWorkerClient
50+ from sqlit .shared .core .debug_events import emit_debug_event
51+ import time
3852
53+ start = time .perf_counter ()
3954 client = ProcessWorkerClient ()
55+ elapsed_ms = (time .perf_counter () - start ) * 1000.0
56+ emit_debug_event (
57+ "process_worker.startup" ,
58+ category = "process_worker" ,
59+ method = "main-thread" ,
60+ elapsed_ms = elapsed_ms ,
61+ success = True ,
62+ )
63+ emit_debug_event (
64+ "process_worker.use" ,
65+ category = "process_worker" ,
66+ cached = False ,
67+ path = "sync" ,
68+ )
4069 self ._process_worker_client = client
4170 self ._process_worker_client_error = None
4271 self ._touch_process_worker ()
4372 return client
4473 except Exception as exc :
74+ try :
75+ from sqlit .shared .core .debug_events import emit_debug_event
76+ import time
77+
78+ elapsed_ms = (time .perf_counter () - start ) * 1000.0 if start is not None else None
79+ emit_debug_event (
80+ "process_worker.startup" ,
81+ category = "process_worker" ,
82+ method = "main-thread" ,
83+ elapsed_ms = elapsed_ms ,
84+ success = False ,
85+ error = str (exc ),
86+ )
87+ except Exception :
88+ pass
4589 self ._process_worker_client_error = str (exc )
4690 try :
4791 self .log .error (f"Failed to start process worker: { exc } " )
@@ -51,20 +95,71 @@ def _get_process_worker_client(self: QueryMixinHost) -> Any | None:
5195
5296 async def _get_process_worker_client_async (self : QueryMixinHost ) -> Any | None :
5397 import asyncio
98+ import sys
5499
55100 client = getattr (self , "_process_worker_client" , None )
56101 if client is not None :
102+ try :
103+ from sqlit .shared .core .debug_events import emit_debug_event
104+
105+ emit_debug_event (
106+ "process_worker.use" ,
107+ category = "process_worker" ,
108+ cached = True ,
109+ path = "async" ,
110+ )
111+ except Exception :
112+ pass
57113 self ._touch_process_worker ()
58114 return client
115+ start = None
59116 try :
60117 from sqlit .domains .process_worker .app .process_worker_client import ProcessWorkerClient
118+ from sqlit .shared .core .debug_events import emit_debug_event
119+ import time
61120
62- client = await asyncio .to_thread (ProcessWorkerClient )
121+ start = time .perf_counter ()
122+ if sys .platform == "darwin" :
123+ # Avoid forking from a background thread on macOS; it can crash pre-exec.
124+ client = ProcessWorkerClient ()
125+ method = "main-thread"
126+ else :
127+ client = await asyncio .to_thread (ProcessWorkerClient )
128+ method = "to-thread"
129+ elapsed_ms = (time .perf_counter () - start ) * 1000.0
130+ emit_debug_event (
131+ "process_worker.startup" ,
132+ category = "process_worker" ,
133+ method = method ,
134+ elapsed_ms = elapsed_ms ,
135+ success = True ,
136+ )
137+ emit_debug_event (
138+ "process_worker.use" ,
139+ category = "process_worker" ,
140+ cached = False ,
141+ path = "async" ,
142+ )
63143 self ._process_worker_client = client
64144 self ._process_worker_client_error = None
65145 self ._touch_process_worker ()
66146 return client
67147 except Exception as exc :
148+ try :
149+ from sqlit .shared .core .debug_events import emit_debug_event
150+ import time
151+
152+ elapsed_ms = (time .perf_counter () - start ) * 1000.0 if start is not None else None
153+ emit_debug_event (
154+ "process_worker.startup" ,
155+ category = "process_worker" ,
156+ method = "main-thread" ,
157+ elapsed_ms = elapsed_ms ,
158+ success = False ,
159+ error = str (exc ),
160+ )
161+ except Exception :
162+ pass
68163 self ._process_worker_client_error = str (exc )
69164 try :
70165 self .log .error (f"Failed to start process worker: { exc } " )
0 commit comments