python编程(rq调度系统)
2023-09-27 14:27:11 时间
【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱: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
相关文章
- python-nmap使用及案例
- 机器人系统设计与制作:Python语言实现2.5 用Blender制作机器人的三维模型
- 机器人系统设计与制作:Python语言实现2.7 本章小结
- Python自动化运维--系统基础信息模块
- How to create PDF files in a Python/Django application using ReportLab
- 基于Python 实现企业搜索系统(信息检索)【100010418】
- 转 python 随机走动的模拟
- 《Python硬件编程实战》——2.7 在Linux系统中安装Python
- Ubuntu Server无桌面无显示器情况下虚拟屏幕xvfb的安装及设置—ubuntu18.04server服务器系统下为python安装虚拟显示器 (使用jupyter notebook在web端播放openai的gym下保存的运行视频——需安装ipython)
- 双目三维重建系统(双目标定+立体校正+双目测距+点云显示)Python
- Python实例---简单的选课系统
- 推荐系统协同过滤-python实现(基于用户的协同过滤算法,基于物品的协同过滤算法,附数据集)
- 新手学Python之端口扫描系统
- python文件操作
- Python 小案例实战 —— 简易银行存取款查询系统
- curl输出字符JSON格式化:bash: python: 未找到命令