def _write(self):
rows = []
while True:
row = self._queue.get()
if row is None:
break
rows.append(row)
if len(rows) == self._batch:
self._execute_many(rows)
rows = []
if rows:
self._execute_many(rows)
self._conn.commit()
def _execute_many(self, rows):
with self._conn.cursor() as cursor:
fields = self._fields
table = self.table
sql = """INSERT INTO `{table}` ({field}) VALUES ({mark})""".format(
field='`' + '`, `'.join(fields) + '`',
mark=', '.join(['%s'] * len(fields)),
table=table
)
cursor.executemany(sql, rows)def _write(self):
rows = []
while True: