GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Validate ping timeout before reconnecting · PyMySQL/PyMySQL@6ed34dc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pymysql
    • connections.py
    • tests
      • test_ping_timeout.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pymysql/connections.py‎

Copy file name to clipboardExpand all lines: pymysql/connections.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,14 @@ def ping(self, reconnect=False, timeout=None):
625625
DeprecationWarning,
626626
2,
627627
)
628+
if timeout is not None and timeout <= 0:
629+
raise ValueError("timeout should be > 0")
628630
if self._sock is None:
629631
if reconnect:
630632
self.connect()
631633
reconnect = False
632634
else:
633635
raise err.Error("Already closed")
634-
if timeout is not None and timeout <= 0:
635-
raise ValueError("timeout should be > 0")
636636
saved_timeouts = self._read_timeout, self._write_timeout
637637
if timeout is not None:
638638
self._read_timeout = self._write_timeout = timeout
Collapse file

‎pymysql/tests/test_ping_timeout.py‎

Copy file name to clipboardExpand all lines: pymysql/tests/test_ping_timeout.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,12 @@ def test_ping_timeout_must_be_positive():
5656
finally:
5757
server.close()
5858
client.close()
59+
60+
61+
def test_ping_timeout_is_checked_before_reconnect(monkeypatch):
62+
conn = pymysql.connect(defer_connect=True)
63+
calls = []
64+
monkeypatch.setattr(conn, "connect", lambda *args: calls.append(args))
65+
with pytest.warns(DeprecationWarning), pytest.raises(ValueError):
66+
conn.ping(reconnect=True, timeout=0)
67+
assert calls == []

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.