Top Level Namespace
Defined Under Namespace
Classes: Add, Analyze, Array, Build, Clean, Clobber, Command, Commands, Commit, Dev, DevTasks, Doc, Environment, File, Gemspec, Git, Hash, Internet, MSBuild, Project, Projects, Publish, Pull, Push, Setup, Svn, Tag, Tasks, Test, Text, Timer, Update, Upgrade
Constant Summary collapse
- RAKE_DEFAULT_EXISTS =
File.exists?('rake.default')
- SLN_FILES =
FileList.new('*.sln','*/*.sln','*/*/*.sln')
- INFO =
require_relative ‘array.rb’
Array.new
- NUNIT =
FileList.new('bin/**/*.Test.dll')
- TIMER =
Timer.new
- SOURCE =
FileList.new('LICENSE','README','README.md',"Gemfile")
- COMMANDS =
Commands.new
- MSBUILD =
MSBuild.new
- PROJECTS =
Projects.new
Instance Method Summary collapse
-
#run_with_timeout(directory, command, timeout, tick) ⇒ Object
If you think you can do it with Ruby’s Timeout module, think again.
- #run_with_timeout2(directory, command, timeout) ⇒ Object
Instance Method Details
#run_with_timeout(directory, command, timeout, tick) ⇒ Object
If you think you can do it with Ruby’s Timeout module, think again.
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
# File 'lib/dev_commands.rb', line 964 def run_with_timeout(directory,command, timeout, tick) output = '' exit_code=1 begin # Start task in another thread, which spawns a process stdin, stderrout, thread = Open3.popen2e(command, :chdir=>directory) # Get the pid of the spawned process pid = thread[:pid] start = Time.now while (Time.now - start) < timeout and thread.alive? # Wait up to `tick` seconds for output/error data Kernel.select([stderrout], nil, nil, tick) # Try to read the data begin output << stderrout.read_nonblock(BUFFER_SIZE) rescue IO::WaitReadable # A read would block, so loop around for another select rescue EOFError # Command has completed, not really an error... break end end # Give Ruby time to clean up the other thread sleep 1 if thread.alive? # We need to kill the process, because killing the thread leaves # the process alive but detached, annoyingly enough. Process.kill("TERM", pid) else exit_code=thread.value sleep 1 end ensure stdin.close if stdin stderrout.close if stderrout end return [output,exit_code] end |
#run_with_timeout2(directory, command, timeout) ⇒ Object
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'lib/dev_commands.rb', line 1008 def run_with_timeout2(directory,command,timeout) # stdout, stderr pipes rout, wout = IO.pipe rerr, werr = IO.pipe output='' error='' exit_code=1 pid = Process.spawn(command, :chdir => directory, :out => wout, :err => werr) begin Timeout.timeout(timeout) do exit_code = Process.wait2(pid) output = rout.readlines.join("\n") error = rerr.readlines.join("\n") end rescue Proces.kill('TERM',pid) output = output + 'timeout occurred.' ensure rout.close rerr.close end [output,exit_code] end |