hystrix启发的延迟和容错库。

pycopine的Python项目详细描述


pycopine是一个延迟和容错库,用于隔离 访问远程系统、服务和第三方库,停止级联 在复杂的分布式系统中,当发生故障时 是不可避免的。

正如这篇文章所暗示的,皮科平深受 Hystrix

先决条件

pycopine需要python 3.2+,但将来可能会被移植到2.7。

安装

Pycopine还没有发布。

(计划)功能

  • 检测并报告失败的服务。
  • 短路服务,在高负荷下故障,以帮助他们恢复。
  • 监控故障率和性能指标以检测瓶颈。
  • 在运行时,从任何地方按需管理线程池和队列大小。
  • …(更多内容)

示例

假设我们要与速度慢、不可靠或两者兼而有之的远程服务通话:

importtimeimportrandomdefcrappy_service(input):''' The most useless piece of code ever.'''time.sleep(5)if'OK'!=random.choice(['OK','OK','f**ck']):raiseRuntimeError('We broke something.')returninput

你可以在这个问题上抛出很多线程和try/except子句 不要破坏互联网。或者您可以使用pycopine:

frompycopineimportCommandclassMyCommand(Command):''' Does nothing with the input, but with style. '''defrun(self,input):returncrappy_service(input)deffallback(self,input):returninput# Run and wait for the resultresult=MyCommand('input').result()# Give up after 2 secondsresult=MyCommand('input').result(timeout=2)# Fire and forgetMyCommand('input').submit()# Do stuff in parallelfoo=MyCommand('input_a').submit()bar=MyCommand('input_b').submit()results=[foo.result(),bar.result()]# Change your mind midway throughfoobar=MyCommand('input').submit()iffoobar.wait(timeout=2):result=foobar.reault()else:foobar.cancel(RuntimeError('No time for this sh**t'))

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

推荐PyPI第三方库


热门话题
Grails2.1.0/Java7在Windows8.1上从何处获取当前用户名?   JavaSpringJMSActiveMQ   java异常处理,捕获导致while循环停止   sql server 2008将日期时间解析为JAVA日期   java是第一个servlet,但无法打开它   如何在Java中使用XML bean创建典型的XML头?   java将iOs应用程序转换为Android   java将jsp页面内容读取到其他jsp页面中的html   客户端计算机中小型数据库应用程序的java实现   java同步和ServletContextListener   安卓 Java将所有转义字符替换为双转义   当我在布局单元中实现ScrollView时,java GridView的setOnItemLongClickListener不起作用(使用适配器)   禁用Java web服务端点Wsdl   java如何编写一个程序来反转用户输入的数字