python编程(rq调度系统)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】


    昨天看到一个基于python的队列调度系统,觉得挺有意思。项目的地址在。基本操作步骤如下,


1、安装redis、rq的python库

sudo pip install redis
sudo pip install rq

2、编写work.py

import requests

def count_words_at_url(url):
    resp = requests.get(url)
    return len(resp.text.split())

3、编写process.py

from redis import Redis
from rq import Queue

q = Queue(connection=Redis())
from work import count_words_at_url
result = q.enqueue(count_words_at_url, 'https://www.baidu.com')

4、运行process.py,这个时候只是将工作压进堆栈

python process.py

5、开启工作进程

rq worker

6、此时,你就可以看到计算机结果了

feixiaoxing@hp330:~$ rq worker
08:35:08 RQ worker u'rq:worker:hp330.27580' started, version 0.10.0
08:35:08 *** Listening on default...
08:35:08 Cleaning registries for queue: default
08:35:08 default: work.count_words_at_url('https://www.baidu.com') (6deae914-53be-45a1-acc9-9c5c5fc65c6c)
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:334: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:132: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecurePlatformWarning
08:35:08 default: Job OK (6deae914-53be-45a1-acc9-9c5c5fc65c6c)
08:35:08 Result is kept for 500 seconds

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式-老费

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值