@@ -46,12 +46,12 @@ def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
46
46
self .on_error_future : asyncio .Future
47
47
self .on_message = lambda _ : None
48
48
49
- self .wait_until_started : asyncio .Future = loop .create_future ()
50
- self ._wait_until_started_set_success = (
51
- lambda : self .wait_until_started .set_result (True )
49
+ self .wait_until_initialized : asyncio .Future = loop .create_future ()
50
+ self ._wait_until_initialized_set_success = (
51
+ lambda : self .wait_until_initialized .set_result (True )
52
52
)
53
- self ._wait_until_started_set_exception = (
54
- lambda exc : self .wait_until_started .set_exception (exc )
53
+ self ._wait_until_initialized_set_exception = (
54
+ lambda exc : self .wait_until_initialized .set_exception (exc )
55
55
)
56
56
57
57
@abstractmethod
@@ -88,7 +88,9 @@ def deserialize_message(self, data: bytes) -> Any:
88
88
89
89
90
90
class PipeTransport (Transport ):
91
- def __init__ (self , loop : asyncio .AbstractEventLoop , driver_executable : Path ) -> None :
91
+ def __init__ (
92
+ self , loop : asyncio .AbstractEventLoop , driver_executable : Path
93
+ ) -> None :
92
94
super ().__init__ (loop )
93
95
self ._stopped = False
94
96
self ._driver_executable = driver_executable
@@ -115,17 +117,11 @@ async def run(self) -> None:
115
117
stderr = _get_stderr_fileno (),
116
118
limit = 32768 ,
117
119
)
118
- except FileNotFoundError :
119
- self ._wait_until_started_set_exception (
120
- Error (
121
- "playwright's driver is not found, You can read the contributing guide "
122
- "for some guidance on how to get everything setup for working on the code "
123
- "https://github.com/microsoft/playwright-python/blob/master/CONTRIBUTING.md"
124
- )
125
- )
120
+ except Exception as exc :
121
+ self ._wait_until_initialized_set_exception (exc )
126
122
return
127
123
128
- self ._wait_until_started_set_success ()
124
+ self ._wait_until_initialized_set_success ()
129
125
130
126
assert proc .stdout
131
127
assert proc .stdin
@@ -161,16 +157,19 @@ def send(self, message: Dict) -> None:
161
157
162
158
class WebSocketTransport (AsyncIOEventEmitter , Transport ):
163
159
def __init__ (
164
- self , loop : asyncio .AbstractEventLoop , ws_endpoint : str , timeout : float = None , headers : Dict [str , str ] = None
160
+ self ,
161
+ loop : asyncio .AbstractEventLoop ,
162
+ ws_endpoint : str ,
163
+ timeout : float = None ,
164
+ headers : Dict [str , str ] = None ,
165
165
) -> None :
166
- super ().__init__ ()
166
+ super ().__init__ (loop )
167
167
Transport .__init__ (self , loop )
168
168
169
169
self ._stopped = False
170
170
self .ws_endpoint = ws_endpoint
171
- self .timeout = timeout
171
+ self .timeout = timeout or 30000
172
172
self .headers = headers
173
- self ._loop : asyncio .AbstractEventLoop
174
173
175
174
def request_stop (self ) -> None :
176
175
self ._stopped = True
@@ -189,17 +188,18 @@ async def run(self) -> None:
189
188
if self .timeout is not None :
190
189
options ["close_timeout" ] = self .timeout / 1000
191
190
options ["ping_timeout" ] = self .timeout / 1000
192
- if self .headers is not None :
191
+
192
+ if self .headers :
193
193
options ["extra_headers" ] = self .headers
194
194
try :
195
195
self ._connection = await websockets .connect (self .ws_endpoint , ** options )
196
196
except Exception as err :
197
- self ._wait_until_started_set_exception (
197
+ self ._wait_until_initialized_set_exception (
198
198
Error (f"playwright's websocket endpoint connection error: { err } " )
199
199
)
200
200
return
201
201
202
- self ._wait_until_started_set_success ()
202
+ self ._wait_until_initialized_set_success ()
203
203
204
204
while not self ._stopped :
205
205
try :
0 commit comments