Skip to content

Commit a18a239

Browse files
committed
Set __connected_ctl = True after connecting
1 parent 9144e8c commit a18a239

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class BinLogStreamReader(object):
1212
'''Connect to replication stream and read event'''
1313

14-
def __init__(self, connection_settings = {}, resume_stream = False, blocking = False, only_events = None, server_id = 255):
14+
def __init__(self, connection_settings={}, resume_stream=False, blocking=False, only_events=None, server_id=255):
1515
'''
1616
resume_stream: Start for latest event of binlog or from older available event
1717
blocking: Read on stream is blocking
@@ -45,6 +45,7 @@ def __connect_to_ctl(self):
4545
self._ctl_connection_settings['db'] = 'information_schema'
4646
self._ctl_connection_settings['cursorclass'] = pymysql.cursors.DictCursor
4747
self._ctl_connection = pymysql.connect(**self._ctl_connection_settings)
48+
self.__connected_ctl = True
4849

4950
def __connect_to_stream(self):
5051
self._stream_connection = pymysql.connect(**self.__connection_settings)
@@ -55,13 +56,13 @@ def __connect_to_stream(self):
5556

5657
if self.__log_file is None:
5758
self.__log_file = log_file
58-
# binlog_pos (4) -- position in the binlog-file to start the stream with
59+
# binlog_pos (4) -- position in the binlog-file to start the stream with
5960
# flags (2) BINLOG_DUMP_NON_BLOCK (0 or 1)
6061
# server_id (4) -- server id of this slave
6162
# binlog-filename (string.EOF) -- filename of the binlog on the master
6263
command = COM_BINLOG_DUMP
6364
prelude = struct.pack('<i', len(self.__log_file) + 11) \
64-
+ int2byte(command)
65+
+ int2byte(command)
6566
if self.__log_pos is None:
6667
if self.__resume_stream:
6768
prelude += struct.pack('<I', log_pos)
@@ -80,9 +81,9 @@ def __connect_to_stream(self):
8081

8182
def fetchone(self):
8283
while True:
83-
if self.__connected_stream == False:
84+
if not self.__connected_stream:
8485
self.__connect_to_stream()
85-
if self.__connected_ctl == False:
86+
if not self.__connected_ctl:
8687
self.__connect_to_ctl()
8788
pkt = None
8889
try:

pymysqlreplication/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection):
4747
def dump(self):
4848
print("=== %s ===" % (self.__class__.__name__))
4949
print("Position: %d" % self.position)
50-
print("Next binlog file: %d" % self.next_binlog)
50+
print("Next binlog file: %s" % self.next_binlog)
5151
print()
5252

5353

0 commit comments

Comments
 (0)