MCPcopy
hub / github.com/PyMySQL/PyMySQL / ping

Method ping

pymysql/connections.py:597–629  ·  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

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."""

Callers 3

test_init_commandMethod · 0.80
test_issue_114Method · 0.80
test_pingMethod · 0.80

Calls 3

connectMethod · 0.95
_execute_commandMethod · 0.95
_read_ok_packetMethod · 0.95

Tested by 3

test_init_commandMethod · 0.64
test_issue_114Method · 0.64
test_pingMethod · 0.64