Skip to content

Optimizing version check to happen once per run #597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 20, 2023
Merged
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
8 changes: 5 additions & 3 deletions pymysqlreplication/binlogstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
# 2006 MySQL server has gone away
MYSQL_EXPECTED_ERROR_CODES = [2013, 2006]

PYMYSQL_VERSION_LT_06 = Version(pymysql.__version__) < Version("0.6")


class ReportSlave(object):
"""Represent the values that you may report when connecting as a slave
Expand Down Expand Up @@ -330,7 +332,7 @@ def _register_slave(self):

packet = self.report_slave.encoded(self.__server_id)

if Version(pymysql.__version__) < Version("0.6"):
if PYMYSQL_VERSION_LT_06:
self._stream_connection.wfile.write(packet)
self._stream_connection.wfile.flush()
self._stream_connection.read_packet()
Expand Down Expand Up @@ -502,7 +504,7 @@ def __connect_to_stream(self):
# encoded_data
prelude += gtid_set.encoded()

if Version(pymysql.__version__) < Version("0.6"):
if PYMYSQL_VERSION_LT_06:
self._stream_connection.wfile.write(prelude)
self._stream_connection.wfile.flush()
else:
Expand Down Expand Up @@ -588,7 +590,7 @@ def fetchone(self):
self.__connect_to_ctl()

try:
if Version(pymysql.__version__) < Version("0.6"):
if PYMYSQL_VERSION_LT_06:
pkt = self._stream_connection.read_packet()
else:
pkt = self._stream_connection._read_packet()
Expand Down