设置使用频率限制。阅读更多:https://github.com/ClericPy/frequency_控制器。

frequency-controller的Python项目详细描述


频率控制器PyPIGitHub Workflow StatusPyPI - WheelPyPI - Python VersionPyPI - DownloadsPyPI - License

频率限制。从torequests复制的代码段。在

简介

  1. There are many implementations for frequency-control, the generator way is better than using a Queue
    1. Queue instances use more memory
    2. Queue initial process is slower than create a generator
  2. Python3.8+ required the lock protection for async-generators.
    1. https://bugs.python.org/issue38559
    2. But 3.6 / 3.7 don't have this feature
  3. Using timeit.default_timer for a better accuracy but little performance lost.
    1. Frequency.TIMER = timeit.default_timer

安装

pip install -U frequency_controller

快速入门

1。多线程演示

fromfrequency_controllerimportFrequencyfromthreadingimportThreadfromtimeimportstrftimedefsync_demo():# limit to 2 concurrent tasks each 1 secondfrequency=Frequency(2,1)deftest():withfrequency:print(strftime('%Y-%m-%d %H:%M:%S'))threads=[Thread(target=test)for_inrange(5)]fortinthreads:t.start()if__name__=="__main__":sync_demo()# 2020-02-21 18:35:43# 2020-02-21 18:35:43# 2020-02-21 18:35:44# 2020-02-21 18:35:44# 2020-02-21 18:35:45

2。协同程序演示

^{pr2}$

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
算法图形。路径方向Java枚举方向问题无法使用EAST   Java:将字符串转换为特定语言环境   javaspringboot&Thymeleaf为后续调用保存搜索表单的最佳方法   mapreduce程序中未调用java reducer   java如何将url中的Gif文件保存到手机中?   如何在JavaSwing中使用[Esc]键最小化JInternalFrame?   java创建了一个包含100个按钮、80个空按钮和20个随机按钮的网格布局   如何在java中使用数组对2d字符串数组中的每一行进行排序。分类   java无法识别的SSL消息,纯文本连接?例外   为什么Java编译器允许在抛出部分列出方法无法抛出的异常   java将预测数组添加到训练数组   java从Ajax调用获取响应文本   使用改型2的java应用程序等待一分钟后退出