Skip to main content

A flow control packages,control QPS

Project description

Flow Control

  • 功能

    • 这个packages可以控制每秒一个函数或者语句的调用次数,可以设置访问次数和时间间隔,
    • 访问限制 访问次数/时间间隔
  • 使用方法(单进程情况下使用FlowControl 类,多进程情况下使用ProcessFlowControl类)

    #encoding=utf-8
    import os
    import threading
    
    from datetime import datetime
    from flow_control.controller import FlowControl
    from flow_control.controller import ProcessFlowControl
    from threading import Thread
    
    
    
    def work(flowcontrol):
        while True:
            if flowcontrol.get():
                print("{}--{}--{}".format(os.getpid(), threading.currentThread().ident, datetime.now()))
    
    flow_control = FlowControl(num=1, interval=1)
    Thread(target=work, args=(flow_control,)).start()
    work(flow_control)
    
    • 创建一个FlowControl (单进程情况下)或者 ProcessFlowControl(多进程情况下) 对象,参数为(num=访问次数,interval=时间间隔),
    • num的类型应该为int类型,interval应该为int或者float类型
    • 然后调用该对象的 get方法
    • 如果get方法返回 True,则说明可以未达到流控限制,如果返回False则说明函数调用次数或者访问次数已经 达到流控限制,应该拒绝调用或访问

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flow_control-1.0.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

flow_control-1.0.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file flow_control-1.0.0.tar.gz.

File metadata

  • Download URL: flow_control-1.0.0.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for flow_control-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bd6ffad534a716e62b96cf92e20ccd1378d96140a2d2a3ad64eb07e8979e6026
MD5 bd4b03feec83b8f0a129460b32a36332
BLAKE2b-256 65d71705b554e781cf778b5d85449929b2e6b618a262da04e2b2428e34651551

See more details on using hashes here.

File details

Details for the file flow_control-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: flow_control-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for flow_control-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 829ac00f7c8c7542c24c9ed506d2640bd6815bc9c1f8ced13bd589b742105942
MD5 ccc43acefffef41f9554a4dd2cabba7e
BLAKE2b-256 6f5b12dcf46b5b5ac21261ea76ec506cbd2b6ce72892bf26ee58c398944547ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page