| 87 | """ |
| 88 | |
| 89 | def __init__( |
| 90 | self, |
| 91 | async_client_class: "Optional[Type[AsyncHTTPClient]]" = None, |
| 92 | **kwargs: Any, |
| 93 | ) -> None: |
| 94 | # Initialize self._closed at the beginning of the constructor |
| 95 | # so that an exception raised here doesn't lead to confusing |
| 96 | # failures in __del__. |
| 97 | self._closed = True |
| 98 | self._io_loop = IOLoop(make_current=False) |
| 99 | if async_client_class is None: |
| 100 | async_client_class = AsyncHTTPClient |
| 101 | |
| 102 | # Create the client while our IOLoop is "current", without |
| 103 | # clobbering the thread's real current IOLoop (if any). |
| 104 | async def make_client() -> "AsyncHTTPClient": |
| 105 | await gen.sleep(0) |
| 106 | assert async_client_class is not None |
| 107 | return async_client_class(**kwargs) |
| 108 | |
| 109 | self._async_client = self._io_loop.run_sync(make_client) |
| 110 | self._closed = False |
| 111 | |
| 112 | def __del__(self) -> None: |
| 113 | self.close() |