python - 如何使用更多信息记录 APScheduler 警告?

标签 python logging error-handling apscheduler

我正在使用 Python APScheduler运行一堆重复性任务,但是对于一些任务,我现在遇到错误,例如:

WARNING:apscheduler.scheduler:Execution of job "getAndStoreExchangeRate (trigger: cron[minute='*'], next run at: 2014-11-06 18:48:00 CET)" skipped: maximum number of running instances reached (1)



除此之外,这个 APscheduler 实例的内存使用量在运行大约十天后突然上升,从大约 47MiB 到 1200MiB,之后由于机器内存不足,各种进程停止。

因此,要找到问题的根源,我需要准确了解哪些调用会导致这些警告。据我了解,发生此错误是因为上一个调用(此调用前一分钟)尚未结束。但是,此错误中的信息相当模糊。给出了函数的名称( getAndStoreExchangeRate ),但我有多个文件,其中的函数名称如下。所以我想知道的是:
  • 这个函数在哪个文件的哪一行出现警告?
  • 这个函数有哪些参数?

  • 有人知道我如何在某处记录这些信息吗?欢迎所有提示!

    [编辑]

    所以我继承了 BackgroundScheduler 并覆盖了 _process_jobs()我在这个片段中更改了 self._logger.warning 的方法:
    try:
        executor.submit_job(job, run_times)
    except MaxInstancesReachedError:
        self._logger.warning(
            'Execution of job "%s" skipped: maximum number of running instances reached (%d)',
            job, job.max_instances
        )
    except:
        self._logger.exception('Error submitting job "%s" to executor "%s"', job, job.executor)
    

    对此:
    'Execution of job "%s" skipped: maximum number of running instances reached (%d) =-= ARGS: ' + str(job.args) + ' - KWARGS: ' + str(job.kwargs),
    

    这样做的原因是它向我显示了给函数的参数,但我仍然不知道最重要的事情:在哪个文件中以及在哪一行上定义了发生警告的这个函数。有谁知道我怎么能证明这一点?

    最佳答案

    最简单的方法是在 _process_jobs() 方法的 apscheduler.schedulers.base 模块的“除了 MaxInstancesReachedError:” block 中添加额外的日志记录语句。在那里你可以访问job.func,它是工作的目标函数。

    我建议您将您选择的调度程序子类化并复制 _process_jobs 方法代码。然后修改 except MaxInstancesReachedError block :

    try:
        executor.submit_job(job, run_times)
    except MaxInstancesReachedError:
        self._logger.warning('Execution of job "%s" skipped: maximum number of running instances reached (%d)', job.func, job.max_instances)
    

    编辑:

    函数文件名: job.func.__code__.co_filename

    行号: job.func.__code__.co_firSTLineno

    关于python - 如何使用更多信息记录 APScheduler 警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27178778/

    相关文章:

    Python flask 重定向错误

    Pythonlogging.basicConfig为处理程序设置不同的级别

    python 记录 : email entire log file as attachment when level >= ERROR

    php - 错误消息,用于失败的注册,登录等。-使用$ GLOBAL oder $ _SESSION?

    python - "takes 1 positional argument but 2 were given"同时找到函数的最小值

    python PIL : shift the hue and saturation

    python - Sentry 与 Mongodb 兼容吗?

    python - python高效读取数据(仅一行)

    logging - Log4Net : Debug vs Info?

    r - 应该是具有相同水平,误差和引用的因素