Skip to content

Commit

Permalink
merging zenspider's work
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoward committed Mar 13, 2014
2 parents fdaa043 + 5c8572b commit 2bc3782
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
40 changes: 20 additions & 20 deletions lib/open4.rb
Expand Up @@ -4,7 +4,7 @@
require 'thread'

module Open4
VERSION = '1.3.3'
VERSION = '1.3.4'
def Open4.version() VERSION end

def Open4.description
Expand Down Expand Up @@ -183,9 +183,9 @@ def run

begin
@argv.each do |a, b|
@threads << Thread.new(*a) do |*a|
@threads << Thread.new(*a) do |*_a|
begin
b[*a]
b[*_a]
ensure
killall rescue nil if $!
@done.push Thread.current
Expand Down Expand Up @@ -214,9 +214,9 @@ def to timeout = nil

def new_thread *a, &b
cur = Thread.current
Thread.new(*a) do |*a|
Thread.new(*a) do |*_a|
begin
b[*a]
b[*_a]
rescue Exception => e
cur.raise e
end
Expand All @@ -229,8 +229,8 @@ def getopts opts = {}
keys, default, _ = args
catch(:opt) do
[keys].flatten.each do |key|
[key, key.to_s, key.to_s.intern].each do |key|
throw :opt, opts[key] if opts.has_key?(key)
[key, key.to_s, key.to_s.intern].each do |_key|
throw :opt, opts[_key] if opts.has_key?(_key)
end
end
default
Expand Down Expand Up @@ -259,19 +259,19 @@ def relay src, dst = nil, t = nil
q = Queue.new
th = nil

timer_set = lambda do |t|
th = new_thread{ to(t){ q.pop } }
timer_set = lambda do |_t|
th = new_thread{ to(_t){ q.pop } }
end

timer_cancel = lambda do |t|
timer_cancel = lambda do |_t|
th.kill if th rescue nil
end

timer_set[t]
begin
src.each do |buf|
src.each do |_buf|
timer_cancel[t]
send_dst[buf]
send_dst[_buf]
timer_set[t]
end
ensure
Expand Down Expand Up @@ -342,17 +342,17 @@ def spawn arg, *argv

te = ThreadEnsemble.new c

te.add_thread(i, stdin) do |i, stdin|
relay stdin, i, stdin_timeout
i.close rescue nil
te.add_thread(i, stdin) do |_i, _stdin|
relay _stdin, _i, stdin_timeout
_i.close rescue nil
end

te.add_thread(o, stdout) do |o, stdout|
relay o, stdout, stdout_timeout
te.add_thread(o, stdout) do |_o, _stdout|
relay _o, _stdout, stdout_timeout
end

te.add_thread(e, stderr) do |o, stderr|
relay e, stderr, stderr_timeout
te.add_thread(e, stderr) do |_o, _stderr| # HACK: I think this is a bug
relay e, _stderr, stderr_timeout
end

te.run
Expand Down Expand Up @@ -386,7 +386,7 @@ def background arg, *argv
else
argv.push opts
end
thread = Thread.new(arg, argv){|arg, argv| spawn arg, *argv}
thread = Thread.new(arg, argv){|_arg, _argv| spawn _arg, *_argv}
sc = class << thread; self; end
sc.module_eval {
define_method(:pid){ @pid ||= q.pop }
Expand Down
8 changes: 4 additions & 4 deletions open4.gemspec
Expand Up @@ -3,7 +3,7 @@

Gem::Specification::new do |spec|
spec.name = "open4"
spec.version = "1.3.3"
spec.version = "1.3.4"
spec.platform = Gem::Platform::RUBY
spec.summary = "open4"
spec.description = "open child process with handles on pid, stdin, stdout, and stderr: manage child processes and their io handles easily."
Expand All @@ -13,10 +13,10 @@ Gem::Specification::new do |spec|
["LICENSE",
"README",
"README.erb",
"Rakefile",
"lib",
"lib/open4.rb",
"open4.gemspec",
"rakefile",
"samples",
"samples/bg.rb",
"samples/block.rb",
Expand All @@ -28,11 +28,11 @@ Gem::Specification::new do |spec|
"samples/stdin_timeout.rb",
"samples/timeout.rb",
"test",
"test/lib",
"test/lib/test_case.rb",
"test/pfork4_test.rb",
"test/popen4_test.rb",
"test/popen4ext_test.rb",
"test/support",
"test/support/test_case.rb",
"white_box",
"white_box/leak.rb"]

Expand Down
Binary file removed pkg/open4-1.3.3.gem
Binary file not shown.
Binary file added pkg/open4-1.3.4.gem
Binary file not shown.
2 changes: 1 addition & 1 deletion rakefile
Expand Up @@ -32,7 +32,7 @@ def run_tests!(which = nil)

test_rbs.each_with_index do |test_rb, index|
testno = index + 1
command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
command = "#{ This.ruby } -rubygems -w -I ./lib -I ./test/lib #{ test_rb }"

puts
say(div, :color => :cyan, :bold => true)
Expand Down
2 changes: 1 addition & 1 deletion test/support/test_case.rb → test/lib/test_case.rb
Expand Up @@ -13,7 +13,7 @@ class TestCase < MiniTest::Unit::TestCase
class MyError < RuntimeError; end

def on_mri?
::Config::CONFIG['ruby_install_name'] == 'ruby'
::RbConfig::CONFIG['ruby_install_name'] == 'ruby'
end

def wait_status(cid)
Expand Down
2 changes: 1 addition & 1 deletion test/pfork4_test.rb
Expand Up @@ -51,7 +51,7 @@ def test_passes_child_pid_to_block
fun = lambda { $stdout.write Process.pid }
cid_in_block = nil
cid_in_fun = nil
status = pfork4(fun) do |cid, _, stdout, _|
pfork4(fun) do |cid, _, stdout, _|
cid_in_block = cid
cid_in_fun = stdout.read.to_i
end
Expand Down
4 changes: 2 additions & 2 deletions test/popen4_test.rb
Expand Up @@ -8,7 +8,7 @@ class POpen4Test < TestCase

def test_unknown_command_propagates_exception
err = assert_raises(*UNKNOWN_CMD_ERRORS) { popen4 UNKNOWN_CMD }
assert_match /#{UNKNOWN_CMD}/, err.to_s if on_mri?
assert_match(/#{UNKNOWN_CMD}/, err.to_s) if on_mri?
end

def test_exception_propagation_avoids_zombie_child_process
Expand All @@ -31,7 +31,7 @@ def test_passes_child_pid_to_block
cmd = %{ruby -e "STDOUT.print Process.pid"}
cid_in_block = nil
cid_in_fun = nil
status = popen4(cmd) do |cid, _, stdout, _|
popen4(cmd) do |cid, _, stdout, _|
cid_in_block = cid
cid_in_fun = stdout.read.to_i
end
Expand Down
4 changes: 2 additions & 2 deletions test/popen4ext_test.rb
Expand Up @@ -9,7 +9,7 @@ class POpen4Test < TestCase

def test_unknown_command_propagates_exception
err = assert_raises(*UNKNOWN_CMD_ERRORS) { popen4ext true, UNKNOWN_CMD }
assert_match /#{UNKNOWN_CMD}/, err.to_s if on_mri?
assert_match(/#{UNKNOWN_CMD}/, err.to_s) if on_mri?
end

def test_exception_propagation_avoids_zombie_child_process
Expand All @@ -32,7 +32,7 @@ def test_passes_child_pid_to_block
cmd = %{ruby -e "STDOUT.print Process.pid"}
cid_in_block = nil
cid_in_fun = nil
status = popen4ext(true, cmd) do |cid, _, stdout, _|
popen4ext(true, cmd) do |cid, _, stdout, _|
cid_in_block = cid
cid_in_fun = stdout.read.to_i
end
Expand Down

3 comments on commit 2bc3782

@zenspider
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release please?

@ahoward
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged - you need a new gem? ps. ara@dojo4.com for the most di-Rekt experience.

@ahoward
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a:~/git/ahoward/open4 $ git pull
Already up-to-date.
a:~/git/ahoward/open4 $ rake gem
a:~/git/ahoward/open4 $ gem push pkg/open4-1.3.4.gem 
Pushing gem to https://rubygems.org...
Successfully registered gem: open4 (1.3.4)

sorry i was sucking there.

Please sign in to comment.