MCPcopy
hub / github.com/aio-libs/aiohttp / close

Method close

aiohttp/web_ws.py:175–211  ·  view source on GitHub ↗
(self, *, code=1000, message=b'')

Source from the content-addressed store, hash-verified

173
174 @asyncio.coroutine
175 def close(self, *, code=1000, message=b''):
176 if self._writer is None:
177 raise RuntimeError('Call .prepare() first')
178
179 if not self._closed:
180 self._closed = True
181 try:
182 self._writer.close(code, message)
183 except (asyncio.CancelledError, asyncio.TimeoutError):
184 self._close_code = 1006
185 raise
186 except Exception as exc:
187 self._close_code = 1006
188 self._exception = exc
189 return True
190
191 if self._closing:
192 return True
193
194 while True:
195 try:
196 msg = yield from asyncio.wait_for(
197 self._reader.read(),
198 timeout=self._timeout, loop=self._loop)
199 except asyncio.CancelledError:
200 self._close_code = 1006
201 raise
202 except Exception as exc:
203 self._close_code = 1006
204 self._exception = exc
205 return True
206
207 if msg.tp == MsgType.close:
208 self._close_code = msg.data
209 return True
210 else:
211 return False
212
213 @asyncio.coroutine
214 def receive(self):

Callers 15

wait_closedMethod · 0.95
write_eofMethod · 0.95
receiveMethod · 0.95
handlerMethod · 0.95
test_nonstarted_closeMethod · 0.95
test_send_str_closedMethod · 0.95
test_ping_closedMethod · 0.95
test_pong_closedMethod · 0.95
test_close_idempotentMethod · 0.95
goMethod · 0.95

Calls 1

readMethod · 0.45

Tested by 15

handlerMethod · 0.76
test_nonstarted_closeMethod · 0.76
test_send_str_closedMethod · 0.76
test_ping_closedMethod · 0.76
test_pong_closedMethod · 0.76
test_close_idempotentMethod · 0.76
goMethod · 0.76
test_close_excMethod · 0.76
test_close_exc2Method · 0.76