Skip to content

Instantly share code, notes, and snippets.

@kylewelsby
Last active January 2, 2016 09:48
Show Gist options
  • Save kylewelsby/8285170 to your computer and use it in GitHub Desktop.
Save kylewelsby/8285170 to your computer and use it in GitHub Desktop.
require 'redis'
require 'open3'
class Finder
def redis
Redis.new
end
def listen_for_terminate(id)
Thread.new do
loop do
puts 'checking'
if redis.get("terminate:#{id}")
puts "KILL!!!!"
redis.del("terminate:#{id}")
Process.kill('INT', Process.pid)
end
sleep 0.5
end
end
end
def perform
Open3.popen3('find ~') do |stdin, stdout, stderr, wait_thr|
puts stdout.read
end
end
end
Finder.new.tap do |train|
train.listen_for_terminate(1)
train.perform
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment