Broken Pipe Error

881 views
Skip to first unread message

postelrich

unread,
Dec 3, 2014, 10:48:43 AM12/3/14
to pymysq...@googlegroups.com
I have a Python 3.4 program running and about after 8-10 hours, it starts throwing the below exception.  The best I found by searching was to set wait_timeout in my.cnf to a higher value but that hasn't worked.  I'm connecting with pymysql using autocommit.  Any clue on what causes this exception and how to handle it?

Traceback (most recent call last):
  File "/home/ntx/.ntx_path/platform/ntx/common/db.py", line 211, in _executemany
    self.cursor.executemany(statement, params)
  File "/home/ntx/ntx-py3/lib/python3.4/site-packages/pymysql/cursors.py", line 157, in executemany
    self.rowcount = sum(self.execute(query, arg) for arg in args)
  File "/home/ntx/ntx-py3/lib/python3.4/site-packages/pymysql/cursors.py", line 157, in <genexpr>
    self.rowcount = sum(self.execute(query, arg) for arg in args)
  File "/home/ntx/ntx-py3/lib/python3.4/site-packages/pymysql/cursors.py", line 135, in execute
    result = self._query(query)
  File "/home/ntx/ntx-py3/lib/python3.4/site-packages/pymysql/cursors.py", line 274, in _query
    conn.query(q)
  File "/home/ntx/ntx-py3/lib/python3.4/site-packages/pymysql/connections.py", line 713, in query
    self._execute_command(COM_QUERY, sql)
  File "/home/ntx/ntx-py3/lib/python3.4/site-packages/pymysql/connections.py", line 892, in _execute_command
    self._write_bytes(prelude + sql[:chunk_size-1])
  File "/home/ntx/ntx-py3/lib/python3.4/site-packages/pymysql/connections.py", line 852, in _write_bytes
    raise OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")

Naoki INADA

unread,
Dec 12, 2014, 7:55:22 AM12/12/14
to pymysq...@googlegroups.com
Did you set wait_timeout on server, and restert it?
You can confirm your setting is applied correctly with following query.

mysql> select @@wait_timeout;
mysql> select @@global.wait_timeout;

To avoid this error, you can connect and close each time.
Or use connection pool like SQLAlchemy's engine.

Tushar Niras

unread,
Jul 15, 2016, 3:37:14 PM7/15/16
to PyMySQL Users
Yes I'm agree with Naoki. The best practice is open and close connection each time and kepp closed when you're not using.
Reply all
Reply to author
Forward
0 new messages