@@ -129,22 +129,26 @@ def self.run_tasks_parallel(result, task_array, logger)
129
129
130
130
# Waiting for children and handling results
131
131
while pidmap . any?
132
- this_pid , exit_obj = Process . wait2 ( 0 )
133
- next unless this_pid && pidmap . key? ( this_pid )
134
- index = pidmap [ this_pid ] [ :index ]
135
- exitstatus = exit_obj . exitstatus
136
- raise "PID=#{ this_pid } exited abnormally: #{ exit_obj . inspect } " if exitstatus . nil?
137
- raise "PID=#{ this_pid } exited with status #{ exitstatus } " unless exitstatus . zero?
138
-
139
- input = File . read ( File . join ( ipc_tempdir , "#{ this_pid } .dat" ) )
140
- result [ index ] = Marshal . load ( input ) # rubocop:disable Security/MarshalLoad
141
- time_delta = Time . now - pidmap [ this_pid ] [ :start_time ]
142
- pidmap . delete ( this_pid )
143
-
144
- logger . debug "PID=#{ this_pid } completed in #{ time_delta } seconds, #{ input . length } bytes"
145
-
146
- next if result [ index ] . status
147
- return result [ index ] . exception
132
+ pidmap . each do |pid , stuff |
133
+ status = Process . waitpid2 ( pid , Process ::WNOHANG )
134
+ next if status . nil?
135
+ this_pid , exit_obj = status
136
+ next unless this_pid && pidmap . key? ( this_pid )
137
+ index = pidmap [ this_pid ] [ :index ]
138
+ exitstatus = exit_obj . exitstatus
139
+ raise "PID=#{ this_pid } exited abnormally: #{ exit_obj . inspect } " if exitstatus . nil?
140
+ raise "PID=#{ this_pid } exited with status #{ exitstatus } " unless exitstatus . zero?
141
+
142
+ input = File . read ( File . join ( ipc_tempdir , "#{ this_pid } .dat" ) )
143
+ result [ index ] = Marshal . load ( input ) # rubocop:disable Security/MarshalLoad
144
+ time_delta = Time . now - pidmap [ this_pid ] [ :start_time ]
145
+ pidmap . delete ( this_pid )
146
+
147
+ logger . debug "PID=#{ this_pid } completed in #{ time_delta } seconds, #{ input . length } bytes"
148
+
149
+ next if result [ index ] . status
150
+ return result [ index ] . exception
151
+ end
148
152
end
149
153
150
154
logger . debug 'All child processes completed with no exceptions raised'
0 commit comments