我正在将遗留脚本升级到Python3,但是脚本在执行数据库删除命令(DELETE FROM)时挂起。脚本没有显示错误,记录器只包含is_connected结果,这是真的。下面是我的测试脚本,它基于main.py文件,但在重新填充表之前只调用了删除表的内容并重置其自动增量。
这是我的test.py文件。
#!/usr/bin/env python3
import json
import hashlib
from pprint import pprint
import mysql.connector
import configparser
import re
import random
import requests
import sys
import logging
# Load config for database variables
config = configparser.ConfigParser()
config.read("config.ini")
logFile = "logger.log"
# Set up logging
logging.basicConfig(format='%(asctime)s %(message)s', filename=logFile,level=logging.DEBUG)
# Connect to the MySQL database
cnx = mysql.connector.connect(
host=config["MySQL"]["host"],
user=config["MySQL"]["user"],
port=config["MySQL"]["port"],
passwd=config["MySQL"]["password"],
database=config["MySQL"]["database"]
)
cur = cnx.cursor()
logging.debug(cnx.is_connected())
# Clear the database ready to re-import
# Clear lookup tables first
cur.execute("DELETE FROM member_additional_skills")
logging.debug("Delete Done")
cur.execute("ALTER TABLE member_additional_skills AUTO_INCREMENT = 1")
cnx.commit()
logging.debug("Finished!")
print("Done")我已经让它运行了20分钟,在它声明Teue已连接并且进程仍在运行后,仍然没有记录任何其他内容。我是不是漏掉了什么?
*编辑*进程仍然在htop中,但没有使用cpu,所以看起来崩溃了,对吧?在我写这篇文章的时候,我有以下内容作为我的python3 test.py命令行的输出: client_loop: send disconnect: Broken,进程不再在htop中
我应该指出的是,这个表中的行数不超过30行,因此预计它会在毫秒内完成
谢谢
发布于 2021-09-06 13:29:55
您可以使用TrUNCAtE member_additional_skills或DROP member_additional_skills和CREATE member_additional_skills(....)
这要快得多
发布于 2021-09-06 13:52:33
您可能会遇到锁定问题:有时使用MySQL连接器时,表锁不能正确释放。使表格不可更改。
尝试重置数据库,然后重试!
https://stackoverflow.com/questions/69075250
复制相似问题