问题描述
我正在尝试按照 https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs.
我在 Windows 10 WSL1 ubuntu 20.04 上运行.
我使用 sudo apt-get install python3-rq
安装了 rq,rq 的版本是 1.2.2
我使用 pip3 install rq
安装了 python 库,然后是 1.4.0 版.
我的工作代码在 app/tasks.py 中,并且是
导入时间定义示例():print('开始任务')对于我在范围内(1..10):打印(一)#time.sleep(1)print('任务完成')
当我执行 $ rq worker testrq
时,这似乎开始正常,并报告
Worker rq:worker:6080c3a42475423895995e6da528ad2e:开始,版本 1.2.2*** 正在听 testrq...队列的清理注册表:testrq
然后在另一个终端上启动 python3 并发出命令:
>>>从 redis 导入 Redis>>>进口rq>>>q = rq.Queue('testrq', connection=Redis.from_url('redis://'))>>>job = q.enqueue('app.tasks.example')当输入最后一条语句时,监听进程报告以下内容,然后退出:
回溯(最近一次调用最后一次):文件/usr/lib/python3/dist-packages/rq/utils.py",第 169 行,在 utcparse 中返回 datetime.datetime.strptime(string, _TIMESTAMP_FORMAT)文件/usr/lib/python3.8/_strptime.py",第 568 行,在 _strptime_datetimett,分数,gmtoff_fraction = _strptime(数据字符串,格式)文件/usr/lib/python3.8/_strptime.py",第 349 行,在 _strptimeraise ValueError("时间数据 %r 与格式 %r 不匹配" %ValueError: 时间数据 '' 与格式 '%Y-%m-%dT%H:%M:%S.%fZ' 不匹配在处理上述异常的过程中,又发生了一个异常:回溯(最近一次调用最后一次):文件/usr/lib/python3/dist-packages/rq/worker.py",第508行,工作中结果 = self.dequeue_job_and_maintain_ttl(超时)文件/usr/lib/python3/dist-packages/rq/worker.py",第 574 行,在 dequeue_job_and_maintain_ttl结果 = self.queue_class.dequeue_any(self.queues, timeout,文件/usr/lib/python3/dist-packages/rq/queue.py",第 539 行,在 dequeue_any作业 = job_class.fetch(job_id, connection=connection)文件/usr/lib/python3/dist-packages/rq/job.py",第303行,在fetch中作业.刷新()文件/usr/lib/python3/dist-packages/rq/job.py",第 515 行,刷新self.restore(数据)恢复中的文件/usr/lib/python3/dist-packages/rq/job.py",第 478 行self.started_at = str_to_date(obj.get('started_at'))文件/usr/lib/python3/dist-packages/rq/utils.py",第 256 行,在 str_to_date 中返回 utcparse(as_text(date_str))文件/usr/lib/python3/dist-packages/rq/utils.py",第 172 行,utcparsereturn datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ')文件/usr/lib/python3.8/_strptime.py",第 568 行,在 _strptime_datetimett,分数,gmtoff_fraction = _strptime(数据字符串,格式)文件/usr/lib/python3.8/_strptime.py",第 349 行,在 _strptimeraise ValueError("时间数据 %r 与格式 %r 不匹配" %ValueError: 时间数据 '' 与格式 '%Y-%m-%dT%H:%M:%SZ' 不匹配
谁能告诉我如何解决这个问题?谢谢
PS 在搜索互联网时,我确实遇到了 https://github.com/rq/rq/issues/927;不确定这是否相关.
以防万一有人遇到问题...
我设法升级了我的 Windows 10 操作系统并启用了 WSL2.然后任务运行正常,所以我只能假设这是 WSL1 中某个地方的错误.
当然,它立即突出显示了我在 range(1..10)
中的语法错误.哦!Ruby 可能会消失,但显然不会被遗忘!
I'm trying to get a basic rq working following the tutorial at https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs.
I'm running on windows 10 WSL1 ubuntu 20.04.
I installed rq using sudo apt-get install python3-rq
and rq is at version 1.2.2
I installed the python lib using pip3 install rq
and this is then at version 1.4.0.
My worker code is in app/tasks.py and is
import time
def example():
print('Starting task')
for i in range(1..10):
print(i)
#time.sleep(1)
print('Task completed')
When I do $ rq worker testrq
this seems to start ok, and reports
Worker rq:worker:6080c3a42475423895995e6da528ad2e: started, version 1.2.2
*** Listening on testrq...
Cleaning registries for queue: testrq
On another terminal I then start python3 and issue the commands:
>>> from redis import Redis
>>> import rq
>>> q = rq.Queue('testrq', connection=Redis.from_url('redis://'))
>>> job = q.enqueue('app.tasks.example')
When that last statement is entered the listening process reports the following, then exits:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rq/utils.py", line 169, in utcparse
return datetime.datetime.strptime(string, _TIMESTAMP_FORMAT)
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rq/worker.py", line 508, in work
result = self.dequeue_job_and_maintain_ttl(timeout)
File "/usr/lib/python3/dist-packages/rq/worker.py", line 574, in dequeue_job_and_maintain_ttl
result = self.queue_class.dequeue_any(self.queues, timeout,
File "/usr/lib/python3/dist-packages/rq/queue.py", line 539, in dequeue_any
job = job_class.fetch(job_id, connection=connection)
File "/usr/lib/python3/dist-packages/rq/job.py", line 303, in fetch
job.refresh()
File "/usr/lib/python3/dist-packages/rq/job.py", line 515, in refresh
self.restore(data)
File "/usr/lib/python3/dist-packages/rq/job.py", line 478, in restore
self.started_at = str_to_date(obj.get('started_at'))
File "/usr/lib/python3/dist-packages/rq/utils.py", line 256, in str_to_date
return utcparse(as_text(date_str))
File "/usr/lib/python3/dist-packages/rq/utils.py", line 172, in utcparse
return datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ')
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%SZ'
Can anyone please tell me how to fix this? Thanks
PS On searching the internet I did come across https://github.com/rq/rq/issues/927; not sure if this is related or not.
Just in case someone has the some problem ...
I managed to get my Windows 10 OS upgraded and enabled WSL2. The task then ran ok, so I can only assume this was a bug in WSL1 somewhere.
Of course, it immediately highlighted my syntax error in range(1..10)
. Doh! Ruby may be gone, but clearly not forgotten!
这篇关于Redis 队列工作器在 utcparse 中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!