apscheduler定时器时区问题
apscheduler定时器时区问题

apscheduler定时器时区问题

警告内容如下:

PytzUsageWarning: The normalize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
return self.timezone.normalize(next_fire_time)

原因分析:

问题是pytz被认为已弃用,取而代之的是zoneinfo模块及其后端口。问题是pytz被认为已弃用,取而代之的是zoneinfo模块及其后端口。因此,即使您像前面建议的那样直接设置时区参数,您可能会面临来自其他地方的相同警告,直到apsheduler将修正pytz在现代Python版本中的用法。
PytzUsageWarning来自于pytz_deprecation_shim包,它是tzlocal的依赖项。Tzlocal与pytz紧密结合。由于apscheduler对tzlocal的依赖相对放松,你可以安装一个相当老的版本,它没有这样的警告,但对于apsscheduler本身来说仍然可以接受。

网上收集到的方法如下:

方法一:

from apscheduler.schedulers.background import BackgroundScheduler

sched = BackgroundScheduler(timezone='Asia/Shanghai')

看代码意思应该是将时钟设为亚洲上海时区的,但貌似没有什么作用。
方法二:

pip install tzlocal==2.1

我的Python环境tzlocal==4.1,降为2.1之后警告消失,成功解决。

发表回复

您的电子邮箱地址不会被公开。