Check if the server is alive. `reconnect` is deprecated. Create a new connection if you want to reconnect. :param reconnect: If the connection is closed, reconnect. :type reconnect: boolean :raise Error: If the connection is closed and reconnect=False.
(self, reconnect=False)
| 595 | self.query(f"KILL {thread_id:d}") |
| 596 | |
| 597 | def ping(self, reconnect=False): |
| 598 | """ |
| 599 | Check if the server is alive. |
| 600 | |
| 601 | `reconnect` is deprecated. Create a new connection if you want to reconnect. |
| 602 | |
| 603 | :param reconnect: If the connection is closed, reconnect. |
| 604 | :type reconnect: boolean |
| 605 | |
| 606 | :raise Error: If the connection is closed and reconnect=False. |
| 607 | """ |
| 608 | # emit deprecation warning for reconnect. |
| 609 | if reconnect: |
| 610 | warnings.warn( |
| 611 | "The 'reconnect' argument is deprecated. Create a new connection if you want to reconnect.", |
| 612 | DeprecationWarning, |
| 613 | 2, |
| 614 | ) |
| 615 | if self._sock is None: |
| 616 | if reconnect: |
| 617 | self.connect() |
| 618 | reconnect = False |
| 619 | else: |
| 620 | raise err.Error("Already closed") |
| 621 | try: |
| 622 | self._execute_command(COMMAND.COM_PING, "") |
| 623 | self._read_ok_packet() |
| 624 | except Exception: |
| 625 | if reconnect: |
| 626 | self.connect() |
| 627 | self.ping(False) |
| 628 | else: |
| 629 | raise |
| 630 | |
| 631 | def set_charset(self, charset): |
| 632 | """Deprecated. Use set_character_set() instead.""" |