Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python异常:运行时错误:超过最大递归深度/无法打印的运行时错误_Python_Mysql_Mysql Connector_Mysql Connector Python - Fatal编程技术网

Python异常:运行时错误:超过最大递归深度/无法打印的运行时错误

Python异常:运行时错误:超过最大递归深度/无法打印的运行时错误,python,mysql,mysql-connector,mysql-connector-python,Python,Mysql,Mysql Connector,Mysql Connector Python,我在一个脚本上随机得到这个异常,该脚本接收要使用mysql连接器插入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/

我在一个脚本上随机得到这个异常,该脚本接收要使用mysql连接器插入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
第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>)
(,操作错误(),)
(,InterfaceError(),)
这通过上面的log.error行显示在官方日志中,而不是转储异常的标准输出错误文件


非常感谢您的帮助。

这看起来像是罪魁祸首:

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.connection.commit?
log.error("Error committing the operation to MySQL: %s" % cExc)
# self.commit() - WRONG
self.connection.commit()
try:
    self.commit()
except mysql.connector.Error as e:
    log.error("Error committing the operation to MySQL: %s" % e)