python连接远程服务器、并执行sql,Python和Sqlalchemy-连接模式->随机与远程服务器断开连接...

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 &

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值