1、celery4.0以上不支持windows,用pip安装celery
2、启动redis-server.exe服务
3、编辑运行celery_blog2.py
!/usr/bin/python
coding:utf-8
import requests
import time
from celery import Celery
app = Celery('celery_blog2', broker='redis://localhost:6379/1')
@app.task
def fetch_url(url):
resp = requests.get(url)
print 'mhj '+url
def func(urls):
start = time.time()
for url in urls:
fetch_url.delay(url)
print "It took ", time.time()-start, "seconds"
if name == 'main':
func(["http://oneapm.com", "http://jd.com", "https://taobao.com", "http://baidu.com", "http://news.oneapm.com"])
4、在celery_blog2.py目录运行一个worker,用来执行这个
celery -A celery_blog2 worker --loglevel=info