@@ -42,7 +42,6 @@ def _get_stderr_fileno() -> Optional[int]:
4242
4343class Transport (ABC ):
4444 def __init__ (self ) -> None :
45- self .on_error_future : asyncio .Future
4645 self .on_message = lambda _ : None
4746
4847 @abstractmethod
@@ -56,14 +55,9 @@ def dispose(self) -> None:
5655 async def wait_until_stopped (self ) -> None :
5756 pass
5857
59- async def start (self ) -> None :
60- if not hasattr (self , "on_error_future" ):
61- self .on_error_future = asyncio .Future ()
62- self ._loop = asyncio .get_running_loop ()
63-
64- @abstractmethod
6558 async def run (self ) -> None :
66- pass
59+ self ._loop = asyncio .get_running_loop ()
60+ self .on_error_future : asyncio .Future = asyncio .Future ()
6761
6862 @abstractmethod
6963 def send (self , message : Dict ) -> None :
@@ -99,28 +93,17 @@ async def wait_until_stopped(self) -> None:
9993 await self ._proc .wait ()
10094
10195 async def run (self ) -> None :
102- await self . start ()
96+ await super (). run ()
10397 self ._stopped_future : asyncio .Future = asyncio .Future ()
10498
105- try :
106- self ._proc = proc = await asyncio .create_subprocess_exec (
107- str (self ._driver_executable ),
108- "run-driver" ,
109- stdin = asyncio .subprocess .PIPE ,
110- stdout = asyncio .subprocess .PIPE ,
111- stderr = _get_stderr_fileno (),
112- limit = 32768 ,
113- )
114- except FileNotFoundError :
115- self .on_error_future .set_exception (
116- Error (
117- "playwright's driver is not found, You can read the contributing guide "
118- "for some guidance on how to get everything setup for working on the code "
119- "https://github.com/microsoft/playwright-python/blob/master/CONTRIBUTING.md"
120- )
121- )
122- return
123-
99+ self ._proc = proc = await asyncio .create_subprocess_exec (
100+ str (self ._driver_executable ),
101+ "run-driver" ,
102+ stdin = asyncio .subprocess .PIPE ,
103+ stdout = asyncio .subprocess .PIPE ,
104+ stderr = _get_stderr_fileno (),
105+ limit = 32768 ,
106+ )
124107 assert proc .stdout
125108 assert proc .stdin
126109 self ._output = proc .stdin
@@ -177,22 +160,15 @@ async def wait_until_stopped(self) -> None:
177160 await self ._connection .wait_closed ()
178161
179162 async def run (self ) -> None :
180- await self . start ()
163+ await super (). run ()
181164
182165 options : Dict [str , Any ] = {}
183166 if self .timeout is not None :
184167 options ["close_timeout" ] = self .timeout / 1000
185168 options ["ping_timeout" ] = self .timeout / 1000
186-
187169 if self .headers is not None :
188170 options ["extra_headers" ] = self .headers
189- try :
190- self ._connection = await websockets .connect (self .ws_endpoint , ** options )
191- except Exception as err :
192- self .on_error_future .set_exception (
193- Error (f"playwright's websocket endpoint connection error: { err } " )
194- )
195- return
171+ self ._connection = await websockets .connect (self .ws_endpoint , ** options )
196172
197173 while not self ._stopped :
198174 try :
0 commit comments