I'm using a python for my backend API server. My backend connect to a DISTANT Postgres database using SQLALCHEMY (without flask-sqlalchemy because i need that connector even without flask context (for others specific tasks)
My trouble is : Sometime, my SQLConnector crash, saying :
(psycopg2.OperationalError) server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
This happends randomly. I tried to fix it using a flush mechanism, without success...
(for the record, It's in a Docker)
What do I want ? Get a python software (sqlalchemy) grabbing data from a remote database (postgres) periodically, WITHOUT disconnecting randomly over the time
What did I try to fix it trying auto reconnect on error, and change the engine connection without success or proper code snippet
Where I am at ? I'm stuck, i can't figure out HOW to reproduce the bug WHEN I WANT (for faster test/debug process) not avid thoses annoying disconnect on my sql connector
(psycopg2.OperationalError) server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
[SQL: 'INSERT INTO scan_oee (uniqid, id_kanban, created_at, finished, debug) VALUES (%(uniqid)s, %(id_kanban)s, %(created_at)s, %(finished)s, %(debug)s)'] [parameters: {'uniqid': '2a1c80df-e676-456c-9e8e-a1a32a4b4171', 'id_kanban': '1804033-A02-289', 'created_at': '2018-11-07T09:38:00.125942', 'finished': False, 'debug': True}] (Background on this error at: http://sqlalche.me/e/e3q8)
=== BackListener Exception ===
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
cursor.execute(statement, parameters)
psycopg2.OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "backlistener.py", line 126, in
raise e
File "backlistener.py", line 121, in
backlistener.run()
File "backlistener.py", line 112, in run
self.route_data(n)
File "backlistener.py", line 69, in route_data
insert_oee_into_db(n, self.action_stop_oee)
File "/usr/src/app/taktTime.py", line 109, in insert_oee_into_db
db.add(new_scan)
File "/usr/src/app/db/base.py", line 55, in __exit__
self.session_factory.commit()
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 943, in commit
self.transaction.commit()
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 467, in commit
self._prepare_impl()
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 447, in _prepare_impl
self.session.flush()
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2254, in flush
self._flush(objects)
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2380, in _flush
transaction.rollback(_capture_exception=True)
File "/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File &