[前][次][番号順一覧][スレッド一覧]

ruby-changes:51906

From: normal <ko1@a...>
Date: Mon, 30 Jul 2018 17:05:39 +0900 (JST)
Subject: [ruby-changes:51906] normal:r64120 (trunk): bootstraptest/runner.rb: speed up assert_finish with IO.select (take #2)

normal	2018-07-30 17:05:22 +0900 (Mon, 30 Jul 2018)

  New Revision: 64120

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64120

  Log:
    bootstraptest/runner.rb: speed up assert_finish with IO.select (take #2)
    
    Resurrect r63754 in a 1.8-compatible way.  While we're at it,
    add a note to maintain 1.8 compatibility (cf. r63757).

  Modified files:
    trunk/bootstraptest/runner.rb
Index: bootstraptest/runner.rb
===================================================================
--- bootstraptest/runner.rb	(revision 64119)
+++ bootstraptest/runner.rb	(revision 64120)
@@ -6,6 +6,7 @@ https://github.com/ruby/ruby/blob/trunk/bootstraptest/runner.rb#L6
 # Never use optparse in this file.
 # Never use test/unit in this file.
 # Never use Ruby extensions in this file.
+# Maintain Ruby 1.8 compatibility for now
 
 begin
   require 'fileutils'
@@ -374,12 +375,24 @@ def assert_finish(timeout_seconds, tests https://github.com/ruby/ruby/blob/trunk/bootstraptest/runner.rb#L375
     pid = io.pid
     waited = false
     tlimit = Time.now + timeout_seconds
-    while Time.now < tlimit
+    diff = timeout_seconds
+    while diff > 0
       if Process.waitpid pid, Process::WNOHANG
         waited = true
         break
       end
-      sleep 0.1
+      if io.respond_to?(:read_nonblock)
+        if IO.select([io], nil, nil, diff)
+          begin
+            io.read_nonblock(1024)
+          rescue Errno::EAGAIN, EOFError
+            break
+          end while true
+        end
+      else
+        sleep 0.1
+      end
+      diff = tlimit - Time.now
     end
     if !waited
       Process.kill(:KILL, pid)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]