【问题标题】:Getting Bad File descriptor Error in python after catching recursion depth exceeded捕获超出递归深度后,python中出现错误的文件描述符错误
【发布时间】:2020-06-30 14:51:48
【问题描述】:

我正在尝试了解有关 python 中的 dameonizing 过程的更多信息。我运行了下面的代码并得到了两个错误

  1. [2020-03-19 08:43:06,079 40116 MainProcess test.py file_read 35: ERROR] cmp 中超出最大递归深度
  2. [2020-03-19 08:43:08,766 40116 MainProcess test.py file_read 35: ERROR] [Errno 9] 文件描述符错误 [尝试关闭 foo]

虽然 1 有意义,但 2nd 没有。有人可以帮我吗?

def file_read(filename):
    file_content = None
    with open(filename, "r") as file:
        try:
            logging.finfo('loading file %s' % filename)
            file_content = read_meta_file(file)

        except (FileNotFoundError, ApacheConfigError) as err:
            logging.exception(err)

        with daemon.DaemonContext():
            pass

        try:
            file_read(filename)
        except Exception as err:
            logging.ferror(err)
            raise


    return file_content


file_read('foo.txt')

【问题讨论】:

    标签: python operating-system daemon


    【解决方案1】:

    你正在使用递归,即函数调用自身,你必须有一个最终会结束递归的中断条件。在您的代码中,没有任何中断条件。

    【讨论】:

      猜你喜欢
      • 2021-12-11
      • 2017-08-24
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多