Ruby的time out机制
来源:互联网 发布:股票模拟训练软件 编辑:程序博客网 时间:2024/06/09 23:22
Ruby中的timeout机制是这样的:给timeout设置一个超时时限,若timeout后面的块内容执行时间超过了此时限,则引发异常,若没有超过此时限,则按原流程执行,相当于没有timeout。
例1
2
3
4
5
6
7
8
require 'timeout'
begin
timeout(1){sleep(2)}
rescue Exception
puts 'timeout'
ensure
puts '!!!!!'
end
begin
timeout(1){sleep(2)}
rescue Exception
puts 'timeout'
ensure
puts '!!!!!'
end
例2
2
3
4
5
6
7
8
9
require 'timeout'
begin
timeout(2){sleep(1)}
rescue Exception
puts 'timeout'
ensure
puts '!!!!!'
end
begin
timeout(2){sleep(1)}
rescue Exception
puts 'timeout'
ensure
puts '!!!!!'
end
0 0
- Ruby的time out机制
- Ruby的调用机制
- time out
- 实现Time Out功能的MessageDlg
- Tomcat设置Session time out的时间
- eclipse更新time out的问题
- Tomcat设置Session time out的时间
- 504 Gateway Time-out错误的解决方法
- [ruby]修改Time.now的返回值
- Ruby中Time的常用函数
- session time out
- webservice,connection time out。
- Time Out 与 idle
- msyql 各种time out
- snmp request time out?
- pscp connection time out
- SoapUI socket time out
- HTTP Client Time out
- edx 安装 备忘
- linux:RPC1
- JQ 选择器详解
- 读取手机内存和SD卡的空间大小
- 立体字BlockFont
- Ruby的time out机制
- Codeforces Round #222 (Div. 2)
- Django模板例子
- 最近遇到的问题
- 位域
- 通信的几个概念
- python 的logging
- 设置ecshop文章分类或ID取第一张图作为缩略图
- cocos2d-x中luajit的使用