Tornado+Layui+SQLAlchemy(十二)Tornado+SQLAlchemy 连接文件抛异常 MySQL Connection not available.

目的:

连接异常代码:

[E 200516 15:06:40 iostream:565] Uncaught exception, closing connection.
    Traceback (most recent call last):
      File "C:\Python\Python35-32\lib\site-packages\sqlalchemy\engine\base.py", line 1173, in _execute_context
        context = constructor(dialect, self, conn, *args)
      File "C:\Python\Python35-32\lib\site-packages\sqlalchemy\engine\default.py", line 768, in _init_compiled
        self.cursor = self.create_cursor()
      File "C:\Python\Python35-32\lib\site-packages\sqlalchemy\engine\default.py", line 1122, in create_cursor
        return self._dbapi_connection.cursor()
      File "C:\Python\Python35-32\lib\site-packages\sqlalchemy\pool\base.py", line 965, in cursor
        return self.connection.cursor(*args, **kwargs)
      File "C:\Python\Python35-32\lib\site-packages\mysql\connector\connection.py", line 916, in cursor
        raise errors.OperationalError("MySQL Connection not available.")
    mysql.connector.errors.OperationalError: MySQL Connection not available.
    
    The above exception was the direct cause of the following exception:
...

[E 200516 15:06:40 client:1240] Bad message (TypeError('not all arguments converted during string formatting',)): {'threadName': 'Thread-2', 'exc_text': None, 'stack_info': None, 'lineno': 1240, 'process': 7312, 'name': 'root', 'levelname': 'ERROR', 'levelno': 40, 'msecs': 432.6448440551758, 'created': 1589612800.4326448, 'funcName': 'do_task_thread', 'processName': 'MainProcess', 'thread': 12724, 'relativeCreated': 9872.643947601318, 'exc_info': None, 'msg': '执行待下发任务表Exception', 'args': (OperationalError("(mysql.connector.errors.OperationalError) 2055: Lost connection to MySQL server at '127.0.0.1:3307', system error: 10038 在一个非套接字上尝试了一个操作。",),), 'filename': 'client.py', 'pathname': 'D:\\last\\COSONACM\\ACM\\app\\socket\\client\\client.py', 'module': 'client'}

过程:

1、查看代码是否使用while 产生的错误;

2、若是while 才造成的连接错误,解决方案:在每次执行完与数据库相关的操作后,使用 time.sleep(1),让其等待完全关闭连接后再生成新的连接。

3、(个人理解)连接抛异常原因:因为while 执行速度过快,本次数据库操作还未完成,又有新的任务,就会造成数据库连接抛异常。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值