Skip to content

Commit b7f0993

Browse files
committed
Improved logging when child process fails.
1 parent 9999fe1 commit b7f0993

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

lib/async/container/generic.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,20 @@ def wait_until_ready
107107
Console.debug(self) do |buffer|
108108
buffer.puts "Waiting for ready:"
109109
@state.each do |child, state|
110-
buffer.puts "\t#{child.class}: #{state.inspect}"
110+
buffer.puts "\t#{child.inspect}: #{state}"
111111
end
112112
end
113113

114114
self.sleep
115115

116116
if self.status?(:ready)
117+
Console.logger.debug(self) do |buffer|
118+
buffer.puts "All ready:"
119+
@state.each do |child, state|
120+
buffer.puts "\t#{child.inspect}: #{state}"
121+
end
122+
end
123+
117124
return true
118125
end
119126
end

lib/async/container/group.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def wait_for(channel)
137137
protected
138138

139139
def wait_for_children(duration = nil)
140-
Console.debug(self, "Waiting for children...", duration: duration)
140+
Console.debug(self, "Waiting for children...", duration: duration, running: @running)
141+
141142
if !@running.empty?
142143
# Maybe consider using a proper event loop here:
143144
readable, _, _ = ::IO.select(@running.keys, nil, nil, duration)

lib/async/container/process.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ def name= value
122122

123123
# A human readable representation of the process.
124124
# @returns [String]
125-
def to_s
126-
"\#<#{self.class} #{@name}>"
125+
def inspect
126+
"\#<#{self.class} name=#{@name.inspect} status=#{@status.inspect} pid=#{@pid.inspect}>"
127127
end
128128

129+
alias to_s inspect
130+
129131
# Invoke {#terminate!} and then {#wait} for the child process to exit.
130132
def close
131133
self.terminate!
@@ -149,22 +151,26 @@ def terminate!
149151
end
150152

151153
# Wait for the child process to exit.
154+
# @asynchronous This method may block.
155+
#
152156
# @returns [::Process::Status] The process exit status.
153157
def wait
154158
if @pid && @status.nil?
155-
_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)
156-
157-
if @status.nil?
158-
sleep(0.01)
159-
_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)
160-
end
159+
Console.debug(self, "Waiting for process to exit...", pid: @pid)
161160

162-
if @status.nil?
161+
_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)
162+
163+
while @status.nil?
163164
Console.warn(self) {"Process #{@pid} is blocking, has it exited?"}
164-
_, @status = ::Process.wait2(@pid)
165+
166+
sleep(0.1)
167+
168+
_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)
165169
end
166170
end
167171

172+
Console.debug(self, "Process exited.", pid: @pid, status: @status)
173+
168174
return @status
169175
end
170176
end

0 commit comments

Comments
 (0)