- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 nohup
下运行时,我发现 Ruby 脚本有一些令人困惑的行为。基本上我是这样做的:
require 'logger'
logger_file = open('/mnt/dbsdata/output.log', File::WRONLY | File::APPEND | File::CREAT)
LOGGER = Logger.new(logger_file)
LOGGER.level = Logger::INFO
def run_command(cmd,display=true)
if display
LOGGER.info "Executing: #{cmd}"
end
output = `#{cmd} 2>&1` ; results=$?.success?
if ! results
LOGGER.error "FAILED to execute #{cmd}"
LOGGER.error output
return false
end
return true
end
begin
run_command("some_longrunning_command", true)
run_command("some_other_longrunning_command",true)
# etc...
end
这里奇怪的是,无论是像上面那样使用 Logger 还是普通 puts
到 STDOUT (nohup.out),输出时间都偏离了。我想我可以跟踪日志文件并查看实时日志消息(日志消息、执行命令、重复),但是发生的是大量消息刷新以一次性记录许多陈旧消息,在他们的命令执行很久之后已经执行并完成。
从 shell 中执行脚本时:
`nohup ruby myscript.rb &`
当不在 nohup 下运行时,它的行为符合预期。
有没有人遇到过这种情况并且知道好的解决方法?
最佳答案
我不能肯定地说,但这听起来像是一个 IO sync
问题。 I/O 通常被缓冲以提高速度。 RAM 比磁盘快很多,所以读取和写入都是临时存储的,直到代码请求数据,或者磁盘能够接收它。 Ruby 的 IO 类具有 sync=
方法,可让您告诉 Ruby 在写入时立即刷新缓冲区。
这应该有效:
logger_file = open('/mnt/dbsdata/output.log', File::WRONLY | File::APPEND | File::CREAT)
logger_file.sync = true
LOGGER = Logger.new(logger_file)
LOGGER.level = Logger::INFO
为简单起见,您可以使用以下方法为输出创建正确的模式:
logger_file = File.open('/mnt/dbsdata/output.log', 'a')
关于ruby - nohup 下奇怪的 Ruby 输出滞后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19455667/
我有一个简单的应用程序,它读取数据库,然后经过一些操作将结果写入另一个数据库。 第一行代码使用给用户的消息和屏幕日志更新 ui,然后全部包装在带有 using 和其他 try/catch 的 try/
我有一个名为activity的表,其中有一个memberId和一个时间戳。我想找出在给定的月份中有多少成员执行了一项 Activity (即-在 Activity 表中有记录),但在过去12个月中,谁
我有前三列数据。第一个列表示 id 在前一天做了某件事。我试图通过添加一个新变量“new”来从 dat 转到 dat2,该变量执行三件事: 将 yest 的值复制到前一天。但日子并不总是连续的。因此,
我有一个简单的应用程序,它读取数据库,然后经过一些操作将结果写入另一个数据库。 第一行代码使用给用户的消息和屏幕日志更新 ui,然后全部包装在带有 using 和其他 try/catch 的 try/
我有 data.frame,它显示了股票的当前出价和要价以及我当时的信号。 time bid_price ask_price signal 10:10:01.000500
我无法让网站正常运行。它有许多移动背景并使用 css-invert 过滤器。 请看这里: http://epicstudios.de/blackwhite/ 我的问题是,即使是普通计算机也无法处理移动
我创建了一个矩形对象网格并将它们添加到一个 Pane 中。每个矩形都有一个连接到它的鼠标事件监听器,它由 MouseEvent.Entered 触发器触发。当用户将鼠标移到矩形上时,处理程序只是更改矩
感觉我的笔记本电脑不允许控制台应用程序以一定的速度运行,因为我也尝试过其他应用程序,并且它们也随机滞后。我的机器不老,也不应该这样做,它具有i7-4720HQ CPU @ 2.60GHz(8 CPUs
我现在正面临这个问题。当我的页面加载 (DOM) 时,我调用一个返回 1880 张图像的函数,这些图像存储在 Steam 服务器中。 这些图像在回调之后被添加到我的 DOM 中,该回调返回我的数组响应
我正在尝试创建一个每两秒执行一次函数的应用程序。为了实现这一点,我使用 Timer.scheduledTimer 函数。问题是该函数没有按照应有的那样每两秒执行一次。通常应用程序开始时的间隔是 2 秒
我得到了这个 gps 接收器方法,它将一些数据存储到数据库中。 // GPS private void addGPSListener() { globalconstant.db
我有一个 UISwitch,它可以在切换值时更改其上方 UILabel 的文本。每隔一段时间(大约 2% 的时间)文本不会改变。标签的文本被保存到文本文件中,因此我需要准确性。由于这个问题是间歇性的,
我有一个包含用户帖子的表格 View 。每个帖子都有图片、用户名和帖子本身。刷新控件的操作是使用来自 Parse 的数据重新加载表。除了拉动刷新时的极度延迟外,一切都完美无缺。不知道是因为每个单元格里
我有一个“详细信息”页面,其中显示俱乐部的信息。该页面是一个 UIViewController,由按钮和标签组成,以实现这种外观(就像分组的小表格)。当我在设备上加载此页面时,它比我的应用程序中的任何
我有 ActionSheet 的代码,它可以连接的东西有点慢? @IBAction func showAction(_ sender: UIButton) { let actionSheetC
我的桌面应用程序滞后。我认为 java.awt.image.BufferStrategy 中有问题。 private void render() { BufferStrategy bs
你好,我有一个包含多个页面的 viewpager(使用 fragment 状态寻呼机),以及一些 png 作为这些页面的背景。我已经遵循了在 Ui 中显示位图 (http://developer.an
我在 WPF 窗体上有一个 richtextbox 控件。它有 SpellChecking.IsEnabled 设置为 true 并且 VerticalScrollBarVisibility 设置为
在我的 android 应用程序中,我将数据存储在本地 SQLite 数据库中。在这个数据库的大小小于 8-9 MB 之前,一切都很顺利;然而,一旦数据库大小约为 9 MB,它就会继续在 logcat
我正在开发一个简单的 Android 应用程序,它只有一个 Activity ,一个 WebView。它在我的手机(Android 7.1.2 Nougat 版本)上运行良好,但我收到许多用户的投诉,
我是一名优秀的程序员,十分优秀!