问题标签 [aio-mysql]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - 编码/数据库库的数据库连接问题
我有一个错误
在让我的应用程序空闲(0 个对 DB 的请求)几个小时后。我想,数据库模块会创建连接池(确实如此)并在超时后自动重新创建连接,但事实并非如此。
要求 - Python 3.8、FastAPI、数据库[mysql]。
有任何想法吗 ?
主文件
db_config.py
端点示例
python-3.8 - 为 PyMySQL 版本(1.0.2)启用 aiomysql 的任何想法
当前版本 aiomysql 需要 PyMySQL<=0.9.3,>=0.9 有谁知道如何让 aiomysql 与 PyMySQL 1.0.2 一起工作。
python - 为什么运行第二个异步测试会返回一个 got Future连接到不同的循环
我正在尝试做一些集成测试,我直接调用本地数据库。我有 2 个测试一个接一个地执行,但是我收到以下错误。
E RuntimeError: Task <Task pending name='Task-3' coro=<TestDB.test_priority() running at /home/kay/checkpoint/entity-extractor/test/test_db.py:21> cb=[_run_until_complete_cb() at /usr/lib/python3.8/asyncio/base_events.py:184]> 将 Future 附加到另一个循环
/usr/lib/python3.8/asyncio/streams.py:517:运行时错误
==================================================== ============================================ 警告总结 ===== ==================================================== ======================================= test/test_db.py::TestDB::test_db
/ home/kay/.local/share/virtualenvs/entity-extractor-BuK_iA9e/lib/python3.8/site-packages/aiomysql/pool.py:46:DeprecationWarning:循环参数自 Python 3.8 起已弃用,并计划删除在 Python 3.10 中。self._cond = asyncio.Condition(loop=loop)test/test_db.py::TestDB::test_db
/usr/lib/python3.8/asyncio/locks.py:335: DeprecationWarning: 自 Python 3.8 以来不推荐使用循环参数,并计划在 Python 3.10 中删除。锁=锁(循环=循环)test/test_db.py::TestDB::test_db
/usr/lib/python3.8/asyncio/tasks.py:455: DeprecationWarning: 自 Python 3.8 以来不推荐使用循环参数,并计划在 Python 3.10 中删除。返回等待未来-- 文档:https : //docs.pytest.org/en/stable/warnings.html ============================= ==================================================== ========== 简短的测试摘要信息 ===================================== ==================================================== ==== FAILED test/test_db.py::TestDB::test_priority - RuntimeError: Task <Task pending name='Task-3' coro=<TestDB.test_priority()
如果我单独运行测试,它们会起作用。我正在使用 aio-libs 中的一些工具来执行测试。pytest、pytest-asyncio 和 aiomysql。
test_db.py
python-3.x - MySQL连接错误“读取通信数据包时出错”,但仅在一段时间后
我正面临一个我很难弄清楚的问题。我有一个 Python 脚本,它使用aiomysql
它连接到 MySQL 并运行一些查询。
一开始它工作得很好,但过了一段时间,我开始遇到错误,例如:
2021-11-03 10:40:21 36934 [警告] 与数据库的连接 36934 已中止:“数据库”用户:“用户”主机:“本地主机”(读取通信数据包时出错)
查看代码,我有以下回溯:
我正在使用的数据库库是aiomysql
并且我正在使用连接池来处理它。这是代码(以及之后我如何使用它的示例):
我正在使用的请求示例:
我怀疑这个游泳池不知何故弄乱了,后来导致了这些问题,但我无法解释如何或为什么。
如果需要,我很乐意提供任何其他详细信息。
先感谢您。
python - 当另一个协程已经在等待传入数据时调用 readexactly()
使用池连接——aiomysql
我的代码如下所示:
如果发出单个请求,它会连接到 mysql,它会正常运行,但如果同时发出 2 个或更多请求,则会崩溃并抛出此错误:
当另一个协程已经在等待传入数据时调用 readexactly()