使用sqlalchemy (mysql)能正常insert 和 query,在每次 commit之后都进行close。但是 一段时间后 就会报 BrokenPipeError: [Errno 32] Broken pipe的错误。
具体错误如下,求解决方案:
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 741, in _rollback_impl
self._handle_dbapi_exception(e, None, None, None, None)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1384, in _handle_dbapi_exception
exc_info,
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 152, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 739, in _rollback_impl
self.engine.dialect.do_rollback(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2253, in do_rollback
dbapi_connection.rollback()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 686, in rollback
self._execute_command(COM_QUERY, "ROLLBACK")
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 872, in _execute_command
self._write_bytes(prelude + sql[:chunk_size-1])
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 833, in _write_bytes
self.socket.sendall(data)
sqlalchemy.exc.DBAPIError: (builtins.BrokenPipeError) [Errno 32] Broken pipe
(Background on this error at: http://sqlalche.me/e/dbapi)
(, data: "{"uid":"guibo.li","user_type":"none","args":{},"order_by":{},"page":0,"limit":15}"
, )
handler.task_handler find
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 761, in _commit_impl
self.engine.dialect.do_commit(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2241, in do_commit
dbapi_connection.commit()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 681, in commit
self._execute_command(COM_QUERY, "COMMIT")
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 872, in _execute_command
self._write_bytes(prelude + sql[:chunk_size-1])
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 833, in _write_bytes
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 739, in _rollback_impl
self.engine.dialect.do_rollback(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2253, in do_rollback
dbapi_connection.rollback()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 686, in rollback
self._execute_command(COM_QUERY, "ROLLBACK")
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 872, in _execute_command
self._write_bytes(prelude + sql[:chunk_size-1])
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 833, in _write_bytes
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/utils/commons.py", line 94, in wrapper_check_params
return func(**_kwargs)
File "/app/handler/task_handler.py", line 166, in find
db.session.commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/orm/scoping.py", line 162, in do
return getattr(self.registry(), name)(args,*kwargs)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/orm/session.py", line 1027, in commit
self.transaction.commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/orm/session.py", line 498, in commit
t[1].commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1724, in commit
self._do_commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1755, in _do_commit
self.connection._commit_impl()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 763, in _commit_impl
self._handle_dbapi_exception(e, None, None, None, None)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1468, in _handle_dbapi_exception
self._autorollback()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/langhelpers.py", line 79, in exit
compat.reraise(type_, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 153, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1468, in _handle_dbapi_exception
self._autorollback()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 867, in _autorollback
self._root._rollback_impl()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 741, in _rollback_impl
self._handle_dbapi_exception(e, None, None, None, None)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1384, in _handle_dbapi_exception
exc_info,
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 152, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 739, in _rollback_impl
self.engine.dialect.do_rollback(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2253, in do_rollback
dbapi_connection.rollback()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 686, in rollback
self._execute_command(COM_QUERY, "ROLLBACK")
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 872, in _execute_command
self._write_bytes(prelude + sql[:chunk_size-1])
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 833, in _write_bytes
self.socket.sendall(data)
sqlalchemy.exc.DBAPIError: (builtins.BrokenPipeError) [Errno 32] Broken pipe
(Background on this error at: http://sqlalche.me/e/dbapi)
exception raise during api call: (builtins.BrokenPipeError) [Errno 32] Broken pipe
(Background on this error at: http://sqlalche.me/e/dbapi)
None
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 761, in _commit_impl
self.engine.dialect.do_commit(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2241, in do_commit
dbapi_connection.commit()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 681, in commit
self._execute_command(COM_QUERY, "COMMIT")
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 872, in _execute_command
self._write_bytes(prelude + sql[:chunk_size-1])
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 833, in _write_bytes
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 739, in _rollback_impl
self.engine.dialect.do_rollback(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2253, in do_rollback
dbapi_connection.rollback()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 686, in rollback
self._execute_command(COM_QUERY, "ROLLBACK")
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 872, in _execute_command
self._write_bytes(prelude + sql[:chunk_size-1])
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 833, in _write_bytes
self.socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/utils/commons.py", line 94, in wrapper_check_params
return func(**_kwargs)
File "/app/handler/task_handler.py", line 166, in find
db.session.commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/orm/scoping.py", line 162, in do
return getattr(self.registry(), name)(args,*kwargs)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/orm/session.py", line 1027, in commit
self.transaction.commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/orm/session.py", line 498, in commit
t[1].commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1724, in commit
self._do_commit()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1755, in _do_commit
self.connection._commit_impl()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 763, in _commit_impl
self._handle_dbapi_exception(e, None, None, None, None)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1468, in _handle_dbapi_exception
self._autorollback()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/langhelpers.py", line 79, in exit
compat.reraise(type_, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 153, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1468, in _handle_dbapi_exception
self._autorollback()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 867, in _autorollback
self._root._rollback_impl()
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 741, in _rollback_impl
self._handle_dbapi_exception(e, None, None, None, None)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 1384, in _handle_dbapi_exception
exc_info,
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/util/compat.py", line 152, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 739, in _rollback_impl
self.engine.dialect.do_rollback(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2253, in do_rollback
dbapi_connection.rollback()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 686, in rollback
self._execute_command(COM_QUERY, "ROLLBACK")
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 872, in _execute_command
self._write_bytes(prelude + sql[:chunk_size-1])
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 833, in _write_bytes
self.socket.sendall(data)
sqlalchemy.exc.DBAPIError: (builtins.BrokenPipeError) [Errno 32] Broken pipe
(Background on this error at: http://sqlalche.me/e/dbapi)
(, data: "{"uid":"guibo.li","user_type":"none","args":{},"order_by":{},"page":0,"limit":15}"
, )
handler.task_handler find
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/engine/base.py", line 761, in _commit_impl
self.engine.dialect.do_commit(self.connection)
File "/usr/local/lib/python3.5/dist-packages/sqlalchemy/dialects/mysql/base.py", line 2241, in do_commit
dbapi_connection.commit()
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 681, in commit