Giter Club home page Giter Club logo

flow_control's Introduction

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则说明函数调用次数或者访问次数已经 达到流控限制,应该拒绝调用或访问

flow_control's People

Contributors

mt6979 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.