Code Monkey home page Code Monkey logo

pyretimeout's Introduction

pyretimeout

给任务加入超时控制.

import requests
from pyretimetout import *

@retry(5, timeout_duration=2, all_limit=True) # all task timeout in 2s
def go(*args):
    time.sleep(4)
    return aa

go()
Retry count: 0
task is timeout
Retry count: 1
task is timeout
Retry count: 2
task is timeout
Retry count: 3
task is timeout
Retry count: 4
task is timeout


@retry(10, 5) # Retry function to 10 times, each task timeout in 5s
def fetch():
	r = requests.get('http://xiaorui.cc')
	return r.text


fetch()

Install

install

python setup.py install

OR

# pip install pyretimeout

More

To Do List:

  • 现在的all_limit时间有误差,因为signal信号不能秒级别
  • 一些层次的逻辑还可以优化
  • 用多线程的去做尝试,测试通过

pyretimeout's People

Contributors

rfyiamcool avatar

Stargazers

 avatar orangleliu avatar  avatar Jonathan Barratt avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyretimeout's Issues

Hi

重试次数加入了超时的时间,为什么有时候会多出几秒

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.