MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / ping

Method ping

pymysql/connections.py:606–638  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

test_init_commandMethod · 0.80
test_issue_114Method · 0.80

Calls 3

connectMethod · 0.95
_execute_commandMethod · 0.95
_read_ok_packetMethod · 0.95

Tested by 2

test_init_commandMethod · 0.64
test_issue_114Method · 0.64