parallel 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/parallel.rb +31 -14
 - data/lib/parallel/version.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 7c9109c6823e35d9f0dae9d6b525cd210b050801
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0418fc529365106f7d9915e2c8fb0f223835100d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 228a5ed608242b00fefe9303ff83cd94b5fd35a338f1657c6a6d21d1cedb53a7a205a31abb838addb8ef1763319ca88556a5435204781aa95ed364345db06ee7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 962275502b4cabd3ddfd3557616e4939520392beae12d665f90d56638f1cd63143a621e6f7e51b2345fd485bfcd4abbe0d3060171ecff9f0626bd75246481768
         
     | 
    
        data/lib/parallel.rb
    CHANGED
    
    | 
         @@ -199,7 +199,7 @@ module Parallel 
     | 
|
| 
       199 
199 
     | 
    
         
             
              class << self
         
     | 
| 
       200 
200 
     | 
    
         
             
                def in_threads(options={:count => 2})
         
     | 
| 
       201 
201 
     | 
    
         
             
                  count, _ = extract_count_from_options(options)
         
     | 
| 
       202 
     | 
    
         
            -
                  Array.new(count) 
     | 
| 
      
 202 
     | 
    
         
            +
                  Array.new(count) do |i|
         
     | 
| 
       203 
203 
     | 
    
         
             
                    Thread.new { yield(i) }
         
     | 
| 
       204 
204 
     | 
    
         
             
                  end.map!(&:value)
         
     | 
| 
       205 
205 
     | 
    
         
             
                end
         
     | 
| 
         @@ -212,7 +212,16 @@ module Parallel 
     | 
|
| 
       212 
212 
     | 
    
         | 
| 
       213 
213 
     | 
    
         
             
                def each(array, options={}, &block)
         
     | 
| 
       214 
214 
     | 
    
         
             
                  map(array, options.merge(:preserve_results => false), &block)
         
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
      
 215 
     | 
    
         
            +
                end
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
                def any?(*args, &block)
         
     | 
| 
      
 218 
     | 
    
         
            +
                  raise "You must provide a block when calling #any?" if block.nil?
         
     | 
| 
      
 219 
     | 
    
         
            +
                  !each(*args) { |*args| raise Parallel::Kill if block.call(*args) }
         
     | 
| 
      
 220 
     | 
    
         
            +
                end
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
                def all?(*args, &block)
         
     | 
| 
      
 223 
     | 
    
         
            +
                  raise "You must provide a block when calling #all?" if block.nil?
         
     | 
| 
      
 224 
     | 
    
         
            +
                  !!each(*args) { |*args| raise Parallel::Kill unless block.call(*args) }
         
     | 
| 
       216 
225 
     | 
    
         
             
                end
         
     | 
| 
       217 
226 
     | 
    
         | 
| 
       218 
227 
     | 
    
         
             
                def each_with_index(array, options={}, &block)
         
     | 
| 
         @@ -244,13 +253,16 @@ module Parallel 
     | 
|
| 
       244 
253 
     | 
    
         
             
                  options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
         
     | 
| 
       245 
254 
     | 
    
         
             
                  add_progress_bar!(job_factory, options)
         
     | 
| 
       246 
255 
     | 
    
         | 
| 
       247 
     | 
    
         
            -
                  if size == 0
         
     | 
| 
      
 256 
     | 
    
         
            +
                  results = if size == 0
         
     | 
| 
       248 
257 
     | 
    
         
             
                    work_direct(job_factory, options, &block)
         
     | 
| 
       249 
258 
     | 
    
         
             
                  elsif method == :in_threads
         
     | 
| 
       250 
259 
     | 
    
         
             
                    work_in_threads(job_factory, options.merge(:count => size), &block)
         
     | 
| 
       251 
260 
     | 
    
         
             
                  else
         
     | 
| 
       252 
261 
     | 
    
         
             
                    work_in_processes(job_factory, options.merge(:count => size), &block)
         
     | 
| 
       253 
262 
     | 
    
         
             
                  end
         
     | 
| 
      
 263 
     | 
    
         
            +
                  if results
         
     | 
| 
      
 264 
     | 
    
         
            +
                    options[:return_results] ? results : source
         
     | 
| 
      
 265 
     | 
    
         
            +
                  end
         
     | 
| 
       254 
266 
     | 
    
         
             
                end
         
     | 
| 
       255 
267 
     | 
    
         | 
| 
       256 
268 
     | 
    
         
             
                def map_with_index(array, options={}, &block)
         
     | 
| 
         @@ -295,13 +307,18 @@ module Parallel 
     | 
|
| 
       295 
307 
     | 
    
         
             
                def work_direct(job_factory, options, &block)
         
     | 
| 
       296 
308 
     | 
    
         
             
                  self.worker_number = 0
         
     | 
| 
       297 
309 
     | 
    
         
             
                  results = []
         
     | 
| 
       298 
     | 
    
         
            -
                   
     | 
| 
       299 
     | 
    
         
            -
             
     | 
| 
       300 
     | 
    
         
            -
                     
     | 
| 
       301 
     | 
    
         
            -
                       
     | 
| 
      
 310 
     | 
    
         
            +
                  exception = nil
         
     | 
| 
      
 311 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 312 
     | 
    
         
            +
                    while set = job_factory.next
         
     | 
| 
      
 313 
     | 
    
         
            +
                      item, index = set
         
     | 
| 
      
 314 
     | 
    
         
            +
                      results << with_instrumentation(item, index, options) do
         
     | 
| 
      
 315 
     | 
    
         
            +
                        call_with_index(item, index, options, &block)
         
     | 
| 
      
 316 
     | 
    
         
            +
                      end
         
     | 
| 
       302 
317 
     | 
    
         
             
                    end
         
     | 
| 
      
 318 
     | 
    
         
            +
                  rescue
         
     | 
| 
      
 319 
     | 
    
         
            +
                    exception = $!
         
     | 
| 
       303 
320 
     | 
    
         
             
                  end
         
     | 
| 
       304 
     | 
    
         
            -
                  results
         
     | 
| 
      
 321 
     | 
    
         
            +
                  handle_exception(exception, results)
         
     | 
| 
       305 
322 
     | 
    
         
             
                ensure
         
     | 
| 
       306 
323 
     | 
    
         
             
                  self.worker_number = nil
         
     | 
| 
       307 
324 
     | 
    
         
             
                end
         
     | 
| 
         @@ -322,8 +339,8 @@ module Parallel 
     | 
|
| 
       322 
339 
     | 
    
         
             
                          call_with_index(item, index, options, &block)
         
     | 
| 
       323 
340 
     | 
    
         
             
                        end
         
     | 
| 
       324 
341 
     | 
    
         
             
                        results_mutex.synchronize { results[index] = result }
         
     | 
| 
       325 
     | 
    
         
            -
                      rescue 
     | 
| 
       326 
     | 
    
         
            -
                        exception =  
     | 
| 
      
 342 
     | 
    
         
            +
                      rescue
         
     | 
| 
      
 343 
     | 
    
         
            +
                        exception = $!
         
     | 
| 
       327 
344 
     | 
    
         
             
                      end
         
     | 
| 
       328 
345 
     | 
    
         
             
                    end
         
     | 
| 
       329 
346 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -362,8 +379,8 @@ module Parallel 
     | 
|
| 
       362 
379 
     | 
    
         
             
                              worker.work(job_factory.pack(item, index))
         
     | 
| 
       363 
380 
     | 
    
         
             
                            end
         
     | 
| 
       364 
381 
     | 
    
         
             
                            results_mutex.synchronize { results[index] = result } # arrays are not threads safe on jRuby
         
     | 
| 
       365 
     | 
    
         
            -
                          rescue 
     | 
| 
       366 
     | 
    
         
            -
                            exception =  
     | 
| 
      
 382 
     | 
    
         
            +
                          rescue
         
     | 
| 
      
 383 
     | 
    
         
            +
                            exception = $!
         
     | 
| 
       367 
384 
     | 
    
         
             
                            if Parallel::Kill === exception
         
     | 
| 
       368 
385 
     | 
    
         
             
                              (workers - [worker]).each do |w|
         
     | 
| 
       369 
386 
     | 
    
         
             
                                w.thread.kill unless w.thread.nil?
         
     | 
| 
         @@ -431,8 +448,8 @@ module Parallel 
     | 
|
| 
       431 
448 
     | 
    
         
             
                    item, index = job_factory.unpack(data)
         
     | 
| 
       432 
449 
     | 
    
         
             
                    result = begin
         
     | 
| 
       433 
450 
     | 
    
         
             
                      call_with_index(item, index, options, &block)
         
     | 
| 
       434 
     | 
    
         
            -
                    rescue 
     | 
| 
       435 
     | 
    
         
            -
                      ExceptionWrapper.new( 
     | 
| 
      
 451 
     | 
    
         
            +
                    rescue
         
     | 
| 
      
 452 
     | 
    
         
            +
                      ExceptionWrapper.new($!)
         
     | 
| 
       436 
453 
     | 
    
         
             
                    end
         
     | 
| 
       437 
454 
     | 
    
         
             
                    Marshal.dump(result, write)
         
     | 
| 
       438 
455 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/parallel/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: parallel
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.11.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Michael Grosser
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-03-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            email: michael@grosser.it
         
     | 
| 
         @@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       40 
40 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       41 
41 
     | 
    
         
             
            requirements: []
         
     | 
| 
       42 
42 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       43 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 43 
     | 
    
         
            +
            rubygems_version: 2.5.1
         
     | 
| 
       44 
44 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       45 
45 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       46 
46 
     | 
    
         
             
            summary: Run any kind of code in parallel processes
         
     |