Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
## Backward incompatible changes planned in the future.

* `Connection.set_charset(charset)` will be removed after 2024-06
* `Connection.ping(reconnect)` change the default to not reconnect.

## v1.2.0

Release date: TBD

### Breaking changes

* `Connection.ping()` change the default to not reconnect and deprecate `reconnect` argument.
Create a new connection if you want to reconnect. (#1241)

* Error classes in Cursor class are removed. (#1240)

* `connect()` arguments `db` and `passwd` now emit DeprecationWarning.
Expand Down
11 changes: 10 additions & 1 deletion pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,24 @@ def kill(self, thread_id):
raise TypeError("thread_id must be an integer")
self.query(f"KILL {thread_id:d}")

def ping(self, reconnect=True):
def ping(self, reconnect=False):
"""
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.
"""
# emit deprecation warning for reconnect.
if reconnect:
warnings.warn(
"The 'reconnect' argument is deprecated. Create a new connection if you want to reconnect.",
DeprecationWarning,
2,
)
if self._sock is None:
if reconnect:
self.connect()
Expand Down
8 changes: 6 additions & 2 deletions pymysql/tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ def test_issue_114(self):
c.execute("""select @@autocommit;""")
self.assertFalse(c.fetchone()[0])
conn.close()
conn.ping()
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
conn.ping(reconnect=True)
c.execute("""select @@autocommit;""")
self.assertFalse(c.fetchone()[0])
conn.close()
Expand All @@ -369,7 +371,9 @@ def test_issue_114(self):
c.execute("""select @@autocommit;""")
self.assertFalse(c.fetchone()[0])
conn.close()
conn.ping()
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
conn.ping(reconnect=True)
conn.autocommit(True)
c.execute("""select @@autocommit;""")
self.assertTrue(c.fetchone()[0])
Expand Down
Loading