Sha256: 3730d286ee787b238286e5b7a996a91705b5a4ac870bde0adc0548ed2de70994

Contents?: true

Size: 1 KB

Versions: 23

Compression:

Stored size: 1 KB

Contents

# usage:
# ruby -I lib -r session test/threadtest.rb
# SESSION_USE_SPAWN=1 ruby -I lib -r session test/threadtest.rb

%w(lib  ../lib . ..).each{|d| $:.unshift d}
require 'session'

def display obj 
  Thread.critical = true
  STDOUT.print obj
  STDOUT.flush
  ensure
  Thread.critical = false
end

$VERBOSE=nil
STDOUT.sync = true
STDERR.sync = true
STDOUT.puts "Session::VERSION <#{ Session::VERSION }>"
STDOUT.puts "Session.use_spawn <#{ Session.use_spawn ? 'true' : 'false' }>"
STDOUT.puts "the timestamps of each tid should come back about 1 second apart or there are problems..."
STDOUT.puts


threads = []

3.times do |i|
  threads << 
    Thread::new(i) do |i| 
      cmd = 'echo 42; sleep 1;' * 3      
      sh = Session.new #:use_spawn=>true
      sh.execute(cmd) do |o,e| 
        which = o ? 'stdout' : 'stderr'
        line = (o || e).strip
        indent = '| ' * i
        display "#{ indent }tid<#{ i }> #{ which }<#{ line }> time<#{ Time.now.to_f }>\n"
      end
    end
  sleep rand
end

threads.map{|t| t.join}

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
session-3.2.0 sample/threadtest.rb
session-3.1.2 sample/threadtest.rb
session-3.1.1 sample/threadtest.rb
redcar-0.5.1 plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.5 plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.5.6dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.5.5dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.5.4dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.5.3dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.5.2dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.5.1dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.4.1 plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.4 plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.3.10.1dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.3.10.0dev plugins/runnables/vendor/session/sample/threadtest.rb
redcar-0.3.9 plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb
redcar-0.3.9.0dev plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb
redcar-0.3.8.4 plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb
redcar-0.3.8.3 plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb
redcar-0.3.8.2 plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb