- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是一名 DBA,我偶然发现了这样的案例:开发人员运行 irb session (来自 Ruby on Rails 应用程序)。这个 irb 保持数据库连接打开。有时 - 他们忘记了它,它继续“运行” - 什么都不做,但仍在使用一个数据库连接。
我想在他们的 irb 配置中添加某种“空闲超时”。可能吗?怎么做?
最佳答案
这里是一个快速技巧,您可以如何实现它。
请注意,这没有考虑到用户可能正在 irb session 中执行一些长时间运行的任务。它只是查看最后一次输入的时间戳;如果它没有改变,那么它就会完全终止进程:
更新:它现在检查 irb 当前是否正在运行命令,如果是,则忽略任何超时。
# Add some methods to IRB::Context and IRB::Irb
# for easier timeout implementation.
class IRB::Irb
def status
@signal_status
end
end
class IRB::Context
attr_reader :irb
attr_reader :line_no
def is_evaluating?
self.irb.status == :IN_EVAL
end
end
# Implement an auto exit timer thread. Timeout is given in seconds.
module IRB
def self.auto_exit_after(timeout = 60)
Thread.new {
context = IRB.conf[:MAIN_CONTEXT]
last_input = Time.now
last_line = context.line_no
loop {
sleep 10
# Check if irb is running a command
if context.is_evaluating?
# Reset the input time and ignore any timeouts
last_input = Time.now
next
end
# Check for new input
if last_line != context.line_no
# Got new input
last_line = context.line_no
last_input = Time.now
next
end
# No new input, check if idle time exceeded
if Time.now - last_input > timeout
$stderr.puts "\n** IRB exiting due to idle timeout. Goodbye..."
Process.kill("KILL", Process.pid)
end
}
}
end
end
要使用它,请将代码添加到 .irbrc
,或在 irb 启动时自动加载的其他地方,然后启动计时器:
IRB.auto_exit_after(60)
关于ruby - 如何让 irb 长时间闲置后退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22710919/
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 6年前关闭。 Improve this
我的 symfony 应用程序 (3.4.8) 似乎忽略了任何延长 session 的尝试。解决此问题的最佳行动方案是什么?文档非常模糊。 应用程序/配置/security.yml security:
如何在Rails应用程序中设置如果任何用户闲置30分钟或特定时间段,则应自动注销该用户。 任何人都可以提出任何解决方案。我正在使用dev进行身份验证。任何帮助表示赞赏。 最佳答案 您应该使用 Time
我发现 Azure 容器实例 (ACI) 非常令人困惑。在 Azure 容器应用中,如果没有请求,服务将缩减至零并停止计费。然而ACI也有这样的功能吗? 例如,如果我部署一个每月调用一次的容器,并且每
我发现 Azure 容器实例 (ACI) 非常令人困惑。在 Azure 容器应用中,如果没有请求,服务将缩减至零并停止计费。然而ACI也有这样的功能吗? 例如,如果我部署一个每月调用一次的容器,并且每
有谁知道我如何编写一个 Javacript 函数,如果浏览器的 Javascript 引擎空闲了一定时间,该函数返回 true ? 我很乐意使用 mootools/jQuery 等,如果更容易的话,我
下面的方法会在 15 分钟后注销用户。但问题是,即使用户处于事件状态,也会将其注销。 我正在寻找解决方案,当用户在整整 15 分钟内不事件时,该方法将把他注销,而不是该方法不会运行。 public v
我需要我的应用程序在设备闲置一定时间后重新打开。换句话说,我的应用程序不会进入休眠模式并进入黑屏,而是会重新打开(假设它在后台运行)。将其视为“空闲屏幕”应用。 这在理论上相当简单,但我什至不知道它是
我正在制作一个需要监视 Gmail 帐户是否有新邮件的程序,为了尽快收到它们,我正在使用 JavaMail 的闲置功能。这是我用来调用 folder.idle() 的线程中的代码片段: //Run m
我的应用程序通过推送通知执行静默后台获取。一切正常,当用户在过去 60 分钟内打开应用程序或在 60 分钟内发送推送通知时,从我们的服务器发送的推送通知会按预期触发静默后台提取 - 即使设备已锁定。
在我的 raspberry pi(raspbian 运行)上,我想在空闲系统 5 分钟后(没有鼠标或键盘操作)将当前桌面切换到桌面 n#0,通过 wmctrl -s 0 和 xprintidle 用于
在 iOS 应用程序中,您可以设置 application.idleTimerDisabled = YES 以防止手机自动锁定。 我需要在移动版 Safari 中为像 Doodle Jump 这样的游
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我一直在 AWS Lambda 中修改 nodejs 代码,由一些 API 网关端点调用。我注意到在没有任何 API 网关调用的情况下经过一定时间后,下一个 API 网关请求将超时。我将收到标准的 L
我是一名优秀的程序员,十分优秀!