| 366 | """ |
| 367 | |
| 368 | def __init__( |
| 369 | self, |
| 370 | url: Optional[Union[str, Url]] = None, |
| 371 | timeout: Optional[float] = None, |
| 372 | container: Optional[Container] = None, |
| 373 | ssl_domain: Optional['SSLDomain'] = None, |
| 374 | heartbeat: Optional[float] = None, |
| 375 | urls: Optional[List[str]] = None, |
| 376 | reconnect: Union[None, Literal[False], 'Backoff'] = None, |
| 377 | **kwargs |
| 378 | ) -> None: |
| 379 | self.disconnected = False |
| 380 | self.timeout = timeout or 60 |
| 381 | self.container = container or Container() |
| 382 | self.container.timeout = self.timeout |
| 383 | self.container.start() |
| 384 | self.conn = None |
| 385 | self.closing = False |
| 386 | # Preserve previous behaviour if neither reconnect nor urls are supplied |
| 387 | if url is not None and urls is None and reconnect is None: |
| 388 | reconnect = False |
| 389 | url = Url(url).defaults() |
| 390 | failed = True |
| 391 | try: |
| 392 | self.conn = self.container.connect(url=url, handler=self, ssl_domain=ssl_domain, reconnect=reconnect, |
| 393 | heartbeat=heartbeat, urls=urls, **kwargs) |
| 394 | self.wait(lambda: not (self.conn.state & Endpoint.REMOTE_UNINIT), |
| 395 | msg="Opening connection") |
| 396 | failed = False |
| 397 | finally: |
| 398 | if failed and self.conn: |
| 399 | self.close() |
| 400 | |
| 401 | def create_sender( |
| 402 | self, |