每个 python\django 进程单个 MySQL 会话
如果在 python\django 程序开始时我加载一个执行原始自定义 sql 命令的模块,例如
from django.db import connection
cursor = connection.cursor()
cursor.execute("SET SESSION wait_timeout=2147483")
更改 会话 变量,它是否会在程序运行的所有其余部分中保持不变?即该模块是否与在同一 python\django 进程中运行的其余代码位于同一 MySQL 会话中?
If at the start of a python\django program I load a module that executes a raw custom sql command such as
from django.db import connection
cursor = connection.cursor()
cursor.execute("SET SESSION wait_timeout=2147483")
thus changing a session variable, will it hold for all the rest of the program run? i.e. is the module in the same MySQL session as the rest of the code running in the same python\django process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可靠。
正确的方法是在数据库设置的
OPTIONS
字典中使用init_command
:Not reliably.
The correct way to do this is to use
init_command
within theOPTIONS
dictionary of the db settings: