我正在尝试让 Redis 和 rq 正常工作。
这是我的主要代码:
from rq import Queue from redis import Redis from util import count_words_at_url from rq.registry import FailedJobRegistry, Job 导入时间
如果名称== '主要':
print('Hi')
# Tell RQ what Redis connection to use
redis_conn = Redis()
q = Queue(connection=redis_conn) # no args implies the default queue
# Delay execution of count_words_at_url('http://nvie.com')
job = q.enqueue(count_words_at_url, 'http://nvie.com')
registry = FailedJobRegistry(queue=q)
# Show all failed job IDs and the exceptions they caused during runtime
for job_id in registry.get_job_ids():
job = Job.fetch(job_id, connection=redis_conn)
print(job_id, job.exc_info)
print(job.result)
# Now, wait a while, until the worker is finished
time.sleep(20)
print(job.result)
我的后台任务是:
导入请求
def count_words_at_url(url): resp = requests.get(url) return len(resp.text.split())
我在控制台中得到这个输出:
Hi
a6d5bb76-7bc9-46e4-b6ba-c1f3e3305da8 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
984f6808-0b79-4d64-9bab-a6615ae88eaa Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
02b3ab72-90a9-4366-a160-14cedc9bad68 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
5978089c-d244-4049-b11d-0c3af85c1865 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
8484e4f5-9248-4022-b05b-b3342b1f7978 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
bdd57a11-f1df-4734-956d-254e81480d68 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
cf4eb163-bbd6-46f4-9d54-d34bb2ad9f51 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
ad168c8c-5757-4ef6-93e7-965494d7bf00 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
bcb07749-4839-40a7-ac46-760884cd37a7 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
043bfdb9-5b42-45ba-97c1-b1d8943797a6 Traceback (most recent call last):
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 970, in perform_job
self.prepare_job_execution(job, heartbeat_ttl)
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/worker.py", line 867, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 247, in func_name
self._deserialize_data()
File "/Users/johnvergo/opt/anaconda3/lib/python3.7/site-packages/rq/job.py", line 215, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
ValueError: unsupported pickle protocol: 5
and after 20 seconds, this:
None