【发布时间】:2020-08-31 15:01:10
【问题描述】:
我正在尝试按照https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs 的教程进行基本的 rq 工作。
我在 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 中并且是
import time
def example():
print('Starting task')
for i in range(1..10):
print(i)
#time.sleep(1)
print('Task completed')
当我执行 $ rq worker testrq 时,这似乎开始正常,并报告
Worker rq:worker:6080c3a42475423895995e6da528ad2e: started, version 1.2.2
*** Listening on testrq...
Cleaning registries for queue: testrq
然后我在另一个终端上启动 python3 并发出命令:
>>> from redis import Redis
>>> import rq
>>> q = rq.Queue('testrq', connection=Redis.from_url('redis://'))
>>> job = q.enqueue('app.tasks.example')
当最后一条语句被输入时,监听进程报告如下,然后退出:
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'
谁能告诉我如何解决这个问题?谢谢
PS 在搜索互联网时,我确实遇到了https://github.com/rq/rq/issues/927;不确定这是否相关。
【问题讨论】:
标签: python redis windows-subsystem-for-linux python-rq