Close the connection.
(self)
| 450 | options=options), fetcher, credit=prefetch) |
| 451 | |
| 452 | def close(self) -> None: |
| 453 | """ |
| 454 | Close the connection. |
| 455 | """ |
| 456 | # TODO: provide stronger interrupt protection on cleanup. See PEP 419 |
| 457 | if self.closing: |
| 458 | return |
| 459 | self.closing = True |
| 460 | self.container.errors = [] |
| 461 | try: |
| 462 | if self.conn: |
| 463 | self.conn.close() |
| 464 | self.wait(lambda: not (self.conn.state & Endpoint.REMOTE_ACTIVE), |
| 465 | msg="Closing connection") |
| 466 | if self.conn.transport: |
| 467 | # Close tail to force transport cleanup without waiting/hanging for peer close frame. |
| 468 | self.conn.transport.close_tail() |
| 469 | finally: |
| 470 | self.conn.free() |
| 471 | # Nothing left to block on. Allow reactor to clean up. |
| 472 | self.run() |
| 473 | if self.conn: |
| 474 | self.conn.handler = None # break cyclical reference |
| 475 | self.conn = None |
| 476 | self.container.stop_events() |
| 477 | self.container = None |
| 478 | |
| 479 | @property |
| 480 | def url(self) -> str: |