- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 mysql-connector 接收要插入 mysql 数据库的项目的脚本上随机遇到此异常:
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 77, in emit
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 77, in emit
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 79, in emit
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 79, in emit
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 79, in emit
logging.FileHandler.emit(self, record)
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 930, in emit
StreamHandler.emit(self, record)
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 874, in emit
self.handleError(record)
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 801, in handleError
None, sys.stderr)
File "/opt/python/current2/lib/python2.7/traceback.py", line 124, in print_exception
_print(file, 'Traceback (most recent call last):')
RuntimeError: maximum recursion depth exceeded
Logged from file foo.py, line 47
我偶尔也会得到:
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 77, in emit
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 77, in emit
if self.shouldRollover(record):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 156, in shouldRollover
msg = "%s\n" % self.format(record)
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 723, in format
return fmt.format(record)
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 464, in format
record.message = record.getMessage()
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 322, in getMessage
if not isinstance(msg, basestring):
Traceback (most recent call last):
File "/opt/python/current2/lib/python2.7/logging/handlers.py", line 79, in emit
logging.FileHandler.emit(self, record)
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 930, in emit
StreamHandler.emit(self, record)
File "/opt/python/current2/lib/python2.7/logging/__init__.py", line 874, in emit
self.handleError(record)
RuntimeError: <unprintable RuntimeError object>
Logged from file foo.py, line 47
代码:
import sys
import datetime
import mysql.connector
import config
from logwatch import log
import time, os
class DBConnection:
_dbconn = None
@staticmethod
def get_instance():
if not DBConnection._dbconn:
DBConnection._dbconn = DBConnection()
return DBConnection._dbconn
def __init__(self):
self.connection = None
def connect(self):
if not self.connection:
self.connection = mysql.connector.connect(**config.CONFIG)
def get_cursor(self):
retries = 2
while retries > 0:
try:
self.connect()
cursor = self.connection.cursor(buffered=True)
return cursor
except mysql.connector.errors.InterfaceError, iErr:
log.error("%s: Connection failed. Retrying. " % iErr)
self.connection = None
retries -= 1
if retries == 0:
raise
def execute(self, query, params=None):
cursor = self.get_cursor()
cursor.execute(query, params)
return cursor.rowcount
def commit(self):
try:
self.commit()
except Exception, cExc:
log.error("Error committing the operation to MySQL: %s" % cExc)
def foo(**kwargs):
dml = None
values = None
rows = None
if kwargs['action'] == "check":
dml = "SELECT `log_type` FROM `register` WHERE `record_num` = \
%s AND `log_type` IN ('1', '3')" % kwargs['record_num']
log.info("%s %s Checking if record exists in F/U or SA of db: %s" % (kwargs['rectype'], kwargs['record_num'], dml))
if kwargs['action'] == "moveto":
sections = ['Trash','Follow up','Problem','Scheduled Actions','Information']
if kwargs['section'] == 0:
dml = "UPDATE `register` SET `log_type` = %s WHERE `record_num` = %s"
values = (kwargs['section'], kwargs['record_num'])
else:
dml = "UPDATE `register` SET `log_type` = %s, `comments` = %s WHERE `record_num` = %s"
values = (kwargs['section'], kwargs['status'], kwargs['record_num'])
log.info("%s %s Moving to section '%s' %d: %s" %\
(kwargs['rectype'], kwargs['record_num'], sections[kwargs['section']], kwargs['section'], (dml % values) ))
if kwargs['action'] == "schedule":
yyyymmdd = datetime.datetime.strptime(kwargs['start_date'], '%d%b%y').strftime('%Y-%m-%d')
start_hour = kwargs['start_time'][0:2]
dml = "INSERT INTO `register` (`record_num`,`title`,`sch_date`, \
`sch_time`,`rectype`,`log_type`,`user_id`,`entry`,`site`,`comments`,`category`) VALUES \
(%s, %s, %s, %s, %s, 3, 'FOO', 2, %s, %s, 63)"
values = (kwargs['record_num'], kwargs['title'], yyyymmdd, kwargs['start_time'], kwargs['rectype'], get_site_flag(start_hour), kwargs['comment'])
log.info("%s %s Adding to scheduled actions up for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))
if kwargs['action'] == "update_to_schedule":
yyyymmdd = datetime.datetime.strptime(kwargs['start_date'], '%d%b%y').strftime('%Y-%m-%d')
start_hour = kwargs['start_time'][0:2]
dml = "UPDATE `register` SET `title` = %s,`sch_date` = %s, \
`sch_time` = %s,`rectype` = %s,`log_type` = '3',`user_id` = 'FOO', \
`entry` = '2',`site` = %s WHERE `record_num` = %s LIMIT 1"
values = (kwargs['title'], yyyymmdd, kwargs['start_time'], kwargs['rectype'], get_site_flag(start_hour), kwargs['record_num'])
log.info("%s %s Updating to scheduled actions for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))
if kwargs['action'] == "update_to_follow":
dml = "UPDATE `register` SET `title` = %s,`rectype` = %s, \
`log_type` = '1',`user_id` = 'FOO', `entry` = '2', \
`site` = 'M' WHERE `record_num` = %s LIMIT 1"
values = (kwargs['title'], kwargs['rectype'], kwargs['record_num'])
log.info("%s %s Updating to follow up for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))
if kwargs['action'] == "follow-up":
dml = "INSERT INTO `register` (`record_num`,`title`,`sch_date`, \
`rectype`,`log_type`,`user_id`,`entry`,`site`,`comments`,`category`) VALUES \
(%s, %s, NOW(), %s, 1, 'FOO', 2, 'M',%s, 63)"
values = (kwargs['record_num'], kwargs['title'], kwargs['rectype'], kwargs['comment'] + ', Please follow-up')
log.info("%s %s Adding to follow up for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))
try:
connection = DBConnection.get_instance()
rows = connection.execute(dml, values)
connection.commit()
log.info("%s %s EXECUTE affected %s rows." % (kwargs['rectype'], kwargs['record_num'], rows))
except:
log.error("Error: could not execute %s on db for %s %s.,%s" % ((dml % values), kwargs['rectype'], kwargs['record_num'], str(sys.exc_info())))
return rows
第 47 行是:
log.error("Error committing the operation to MySQL: %s" % cExc)
我应该将其封装在其他东西中吗?抱歉,我不懂Python,我懂Java,我只是想修复我采用的这个脚本。还有其他随机异常,但一次一步,这些似乎在每次提交时都会出现?试图找出这是否是脚本在重压下无法插入数据库的原因,提交是此脚本的新添加,这是其他人尝试修复的。
每当脚本无法插入数据库时,我们也会得到:
(<class 'mysql.connector.errors.OperationalError'>, OperationalError(), <traceback object at 0x2aaaaaf76050>)
(<class 'mysql.connector.errors.InterfaceError'>, InterfaceError(), <traceback object at 0x2aaaaaf75ab8>)
这通过上面的 log.error 行显示在官方日志记录中,而不是转储异常的 stdout 错误文件。
任何帮助将不胜感激,谢谢。
最佳答案
这看起来像是罪魁祸首:
def commit(self):
try:
self.commit()
except Exception, cExc:
log.error("Error committing the operation to MySQL: %s" % cExc)
这是一个无限循环,直到您的递归深度超过系统的限制(通常为 1000)。最后,由于您捕获了所有异常,因此最终会出现
log.error("Error committing the operation to MySQL: %s" % cExc)
尝试
# self.commit() - WRONG
self.connection.commit()
还考虑在提交后不捕获所有异常(被认为是非常糟糕的做法)。替换为 base class for all mysql exceptions相反:
try:
self.commit()
except mysql.connector.Error as e:
log.error("Error committing the operation to MySQL: %s" % e)
关于Python异常: RuntimeError: maximum recursion depth exceeded/unprintable runtime error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30157419/
考虑一下,我们在具有整数弧容量的有向网络中有一个非整数最大流。 是否有算法可以将这个流量转化为整数最大流量? 它的运行时间是多少? 这不是作业问题。 最佳答案 如果您正在寻找具有积分弧容量的最大 s-
我有一个可以接受 byte[] 的 WCF 服务。我正在使用 HttpClient 创建客户端并收到以下错误。我在网上看到你必须在服务器和客户端上设置 readerQuotas,但是如何在 HttpC
我有一个如下所示的数据框: df = pd.DataFrame({'A':[100,300,500,600], 'B':[100,200,300,400],
我开始使用 cocoapi评估使用 Object Detection API 训练的模型。在阅读了解释平均精度 (mAP) 和召回率的各种来源后,我对 cocoapi 中使用的“最大检测”参数感到困惑
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Size-limited queue that holds last N elements in Java Java
您好,我需要帮助制作以下算法: 假设一个二维空间域,具有 xmax、xmin、ymin、ymax,空间中有“n~10,000”个点。 浏览点位置列表。 当框中的点数达到最大数量(假设为 10 个)时,
我在 Android 应用程序中有一个类,它包含一个字节数组作为纹理的数据源。我使用帧缓冲区将一些东西渲染到该纹理上,然后在屏幕上渲染该纹理。这非常有效。 但是,我只能使用 151 个纹理来执行此操作
系统调用中可以传递多少个参数?我检查了内核文件 /asm/unistd.h,没有看到包含超过 4 个参数的系统调用。 最佳答案 这取决于您使用的架构。对于 i386,系统调用号旁边最多有 6 个参数。
题目地址:https://leetcode-cn.com/problems/maximum-average-subtree/ 题目描述 Given the root of a binary tre
题目地址:https://leetcode.com/problems/sliding-window-maximum/ 题目描述 Given an array nums, there is a sl
题目地址:https://leetcode-cn.com/problems/maximum-distance-in-arrays/ 题目描述 Given m arrays, and each ar
题目地址:https://leetcode.com/problems/maximum-average-subarray-i/description/open in new window 题目描述
题目地址:https://leetcode.com/problems/third-maximum-number/description/ 题目描述 Given a non-empty array
我有一个很难重现的错误。另外,有人告诉我写日志文件是一种安全责任。所以我想在异常中尽可能多地捕捉。 我找不到任何说明 C# 异常的最大长度是多少的地方。 我想粘贴一条 XML 消息(1 或 2K),也
是否可以限制 QML 应用的最大 FPS? 我在低端 iten atom 硬件中获得 60FPS 和 30% 的 CPU 使用率使用 win32 Angle 驱动程序(openGL 软件无法使用),我
我已启用 SeriLog(最新版本)自记录功能,并且看到数百条消息说 Maximum destructuring depth reached 不知道这意味着什么以及这是否是我需要担心的问题。 有谁知道
我有一个具有两个属性的模型(我只显示两个,因为只需要这两列) 我的模型 place_id ---------------------- user_id 1 ----------------------
考虑以下情况:要设置一个群集,其中每台计算机都具有32G GB的RAM。和16个CPU核心 如何根据信息(32G GB RAM和16 CPU CORE)确定以下参数 ) yarn.scheduler.
完成如下函数定义: -- maxi x y returns the maximum of x and y 我应该不使用 Haskell 中的“最大”函数来完成这个任务。 maxi :: Int
Haskell 标准库中是否有与 maximum 等效的安全值? *Main Control.Monad.State Data.List> maximum [] *** Exception: Prel
我是一名优秀的程序员,十分优秀!