红宝石,窗户,active_record和控制-C [英] Ruby, windows, active_record, and Control-C

查看:128
本文介绍了红宝石,窗户,active_record和控制-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是active_record做给信号处理windows下(我不认为这与在Mac上的版本相同),导致它表现得如此奇怪?例如:

 需要'rubygems的'
陷阱(INT){看跌期权打断}
把__LINE__
睡眠5
需要'active_record
陷阱(INT){看跌期权再次打断}
把__LINE__
睡眠5
 

当我运行上面的code(红宝石1.8.6,宝石1.3.1,2.2.2的ActiveRecord,)我打^ C多次我第一次在睡眠时喜欢,但之后的第一个中断在需要的ActiveRecord导致脚本终止。在上述情况下,陷阱静止执行时,它不但不能以允许程序继续。通常,

删除捕获第二个呼叫没有在行为产生任何影响。

真正的烦恼是,在某些条件下,陷阱无法执行的。考虑到这样做的整点是让我的code后自己清理(删除其数据库中的足迹,以便未来的家伙看到一个正常的状态,)这是一个真正的问题。例如:

 需要'rubygems的'
需要'active_record
陷阱(INT){看跌期权打断}
把__LINE__
得到
 

pressing ^ C眼看看跌期权将不执行陷阱在所有后。

我只看到需要active_record后这个问题。有没有解决办法?我很好奇,想知道这是否是一个错误,或者有某种的解释。正如我所说的,我有这个在Mac上没有任何问题 - 重复的陷阱进程内的多个执行^铯结果

谢谢...

解决方案
  

考虑到这样做的整点是让我的code后自己清理(删除数据库中的足迹......

你有没有考虑只使用一个数据库事务?看起来这将是一个更简单的方法来解决这个问题。

What is active_record doing to the signal processes under windows (I don't see this with the same versions on the mac) that causes it to behave so strangely? For instance:

require 'rubygems'
trap("INT"){puts "interrupted"}
puts __LINE__
sleep 5
require 'active_record'
trap("INT"){puts "interrupted again"}
puts __LINE__
sleep 5

When I run the above code (ruby 1.8.6, gem 1.3.1, activerecord 2.2.2,) I can hit ^C as many times as I like during the first sleep, but the first interrupt after the require of activerecord causes the script to terminate. In the above case, the trap still executes, it only fails to allow the program to continue. Usually.

Removing the second call to trap does not have any effect upon the behaviors.

The real annoyance is that in some conditions, the trap fails to execute at all. Considering that the whole point of doing this is to get my code to clean up after itself (remove its footprint in the database so the next guy sees a sane state,) this is a real problem. For instance:

require 'rubygems'
require 'active_record'
trap("INT"){puts "interrupted"}
puts __LINE__
gets

Pressing ^C after seeing the puts will not execute the trap at all.

I only see this problem after requiring active_record. Is there a workaround? I'd be curious to know if this is a bug or if there is an explanation of some sort. As I said, I have no issue with this on the mac - repeated ^Cs result in multiple executions of the trap proc.

thanks...

解决方案

Considering that the whole point of doing this is to get my code to clean up after itself (remove its footprint in the database ...

Have you considered just using a database transaction? It seems like it would be a much easier way to solve the problem.

这篇关于红宝石,窗户,active_record和控制-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆