@@ -131,7 +131,8 @@ def run() -> subprocess.Popen[bytes]:
131131 )
132132
133133 _logger .debug ("Trying to open browser." )
134- self .subprocess = await asyncio .to_thread (run )
134+ loop = asyncio .get_running_loop ()
135+ self .subprocess = await loop .run_in_executor (None , run )
135136
136137 super ().__init__ ("0" , self ._broker )
137138 self ._add_session (Session ("" , self ._broker ))
@@ -166,7 +167,8 @@ async def _is_closed(self, wait: int | None = 0) -> bool:
166167 return not _is_open
167168 else :
168169 try :
169- await asyncio .to_thread (self .subprocess .wait , wait )
170+ loop = asyncio .get_running_loop ()
171+ await loop .run_in_executor (None , self .subprocess .wait , wait )
170172 except subprocess .TimeoutExpired :
171173 return False
172174 return True
@@ -184,8 +186,8 @@ async def _close(self) -> None:
184186 return
185187 except ChannelClosedError :
186188 _logger .debug ("Can't send Browser.close on close channel" )
187-
188- await asyncio . to_thread ( self ._channel .close )
189+ loop = asyncio . get_running_loop ()
190+ await loop . run_in_executor ( None , self ._channel .close )
189191
190192 if await self ._is_closed (wait = 3 ):
191193 return
@@ -194,7 +196,8 @@ async def _close(self) -> None:
194196 _logger .debug ("Browser is closed after closing channel" )
195197 return
196198 _logger .warning ("Resorting to unclean kill browser." )
197- await asyncio .to_thread (kill , self .subprocess )
199+ loop = asyncio .get_running_loop ()
200+ await loop .run_in_executor (None , kill , self .subprocess )
198201 if await self ._is_closed (wait = 4 ):
199202 return
200203 else :
@@ -237,12 +240,13 @@ async def _watchdog(self) -> None:
237240 with warnings .catch_warnings ():
238241 warnings .filterwarnings ("ignore" , category = TmpDirWarning )
239242 _logger .debug ("Starting watchdog" )
240- await asyncio .to_thread (self .subprocess .wait )
243+ loop = asyncio .get_running_loop ()
244+ await loop .run_in_executor (None , self .subprocess .wait )
241245 _logger .warning ("Browser is being closed by watchdog." )
242246 self ._watch_dog_task = None
243247 await self .close ()
244248 await asyncio .sleep (1 )
245- await asyncio . to_thread ( self ._browser_impl .clean )
249+ await loop . run_in_executor ( None , self ._browser_impl .clean )
246250
247251 def _add_tab (self , tab : Tab ) -> None :
248252 if not isinstance (tab , Tab ):
0 commit comments