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

Method ping

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

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