@@ -42,7 +42,6 @@ def _get_stderr_fileno() -> Optional[int]:
42
42
43
43
class Transport (ABC ):
44
44
def __init__ (self ) -> None :
45
- self .on_error_future : asyncio .Future
46
45
self .on_message = lambda _ : None
47
46
48
47
@abstractmethod
@@ -56,14 +55,9 @@ def dispose(self) -> None:
56
55
async def wait_until_stopped (self ) -> None :
57
56
pass
58
57
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
65
58
async def run (self ) -> None :
66
- pass
59
+ self ._loop = asyncio .get_running_loop ()
60
+ self .on_error_future : asyncio .Future = asyncio .Future ()
67
61
68
62
@abstractmethod
69
63
def send (self , message : Dict ) -> None :
@@ -99,28 +93,17 @@ async def wait_until_stopped(self) -> None:
99
93
await self ._proc .wait ()
100
94
101
95
async def run (self ) -> None :
102
- await self . start ()
96
+ await super (). run ()
103
97
self ._stopped_future : asyncio .Future = asyncio .Future ()
104
98
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
+ )
124
107
assert proc .stdout
125
108
assert proc .stdin
126
109
self ._output = proc .stdin
@@ -177,22 +160,15 @@ async def wait_until_stopped(self) -> None:
177
160
await self ._connection .wait_closed ()
178
161
179
162
async def run (self ) -> None :
180
- await self . start ()
163
+ await super (). run ()
181
164
182
165
options : Dict [str , Any ] = {}
183
166
if self .timeout is not None :
184
167
options ["close_timeout" ] = self .timeout / 1000
185
168
options ["ping_timeout" ] = self .timeout / 1000
186
-
187
169
if self .headers is not None :
188
170
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 )
196
172
197
173
while not self ._stopped :
198
174
try :
0 commit comments