开发者

Troubles with parallel processes in IRB on Mac

I am working with a database via IRB, and I would like to make periodic changes in the database (e.g., every 10 sec) showing the log in STDOUT.

Also, I would like to have manual control being able to change the database and to stop the first process.

So far I came up to the following

def start
  stop
  @running = Thread.new do
    loop do
      fork do
        puts 'change the database'
      end
      sleep 10
    end
  end
  nil
end

def stop
  @running.kill if @running
end

However, this is not running every 10 sec unless I enter something in the main IRB thread.

How to make it working?开发者_开发问答


Some versions of readline on OSX are blocking. If one experiences the behavior you described, they can disable readline by putting

IRB.conf[:USE_READLINE] = false

in .irbrc


Works fine for me (tested in irb with ruby 1.9.2-p180 and 1.8.7-p334).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜