parallel 1.7.0 → 1.8.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 +38 -11
- data/lib/parallel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cfb32f76c7f232bcd3f44e8370af1e61882de3a
|
4
|
+
data.tar.gz: edab2b1cf2013b37cb7a58908750bfb1221327a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99aa1aaefc20811d7540d607521f76b0edf10b09f5e96d1997341b5a12305d136355ae62e54380d5095111840d2258f8aa09e7a36abff52fdd79cb8f3d392c30
|
7
|
+
data.tar.gz: 3f4255effe94025fa160ec1ef0f47a1a319c7036a4910f762b95218a7ddcc7b118edc60fb884b2ba8af39959e6b74b51d7b16d1dd8d235ed89ec28505997019f
|
data/lib/parallel.rb
CHANGED
@@ -35,15 +35,16 @@ module Parallel
|
|
35
35
|
@read, @write, @pid = read, write, pid
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
38
|
+
def stop
|
39
|
+
close_pipes
|
40
|
+
wait # if it goes zombie, rather wait here to be able to debug
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
# might be passed to started_processes and simultaneously closed by another thread
|
44
|
+
# when running in isolation mode, so we have to check if it is closed before closing
|
45
|
+
def close_pipes
|
46
|
+
read.close unless read.closed?
|
47
|
+
write.close unless write.closed?
|
47
48
|
end
|
48
49
|
|
49
50
|
def work(data)
|
@@ -61,6 +62,14 @@ module Parallel
|
|
61
62
|
raise result.exception if ExceptionWrapper === result
|
62
63
|
result
|
63
64
|
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def wait
|
69
|
+
Process.wait(pid)
|
70
|
+
rescue Interrupt
|
71
|
+
# process died
|
72
|
+
end
|
64
73
|
end
|
65
74
|
|
66
75
|
class JobFactory
|
@@ -300,7 +309,11 @@ module Parallel
|
|
300
309
|
end
|
301
310
|
|
302
311
|
def work_in_processes(job_factory, options, &blk)
|
303
|
-
workers =
|
312
|
+
workers = if options[:isolation]
|
313
|
+
[] # we create workers per job and not beforehand
|
314
|
+
else
|
315
|
+
create_workers(job_factory, options, &blk)
|
316
|
+
end
|
304
317
|
results = []
|
305
318
|
results_mutex = Mutex.new # arrays are not thread-safe
|
306
319
|
exception = nil
|
@@ -308,7 +321,6 @@ module Parallel
|
|
308
321
|
UserInterruptHandler.kill_on_ctrl_c(workers.map(&:pid), options) do
|
309
322
|
in_threads(options) do |i|
|
310
323
|
worker = workers[i]
|
311
|
-
worker.thread = Thread.current
|
312
324
|
|
313
325
|
begin
|
314
326
|
loop do
|
@@ -316,6 +328,12 @@ module Parallel
|
|
316
328
|
item, index = job_factory.next
|
317
329
|
break unless index
|
318
330
|
|
331
|
+
if options[:isolation]
|
332
|
+
worker = replace_worker(job_factory, workers, i, options, blk)
|
333
|
+
end
|
334
|
+
|
335
|
+
worker.thread = Thread.current
|
336
|
+
|
319
337
|
begin
|
320
338
|
result = with_instrumentation item, index, options do
|
321
339
|
worker.work(job_factory.pack(item, index))
|
@@ -332,8 +350,7 @@ module Parallel
|
|
332
350
|
end
|
333
351
|
end
|
334
352
|
ensure
|
335
|
-
worker.
|
336
|
-
worker.wait # if it goes zombie, rather wait here to be able to debug
|
353
|
+
worker.stop if worker
|
337
354
|
end
|
338
355
|
end
|
339
356
|
end
|
@@ -341,6 +358,16 @@ module Parallel
|
|
341
358
|
handle_exception(exception, results)
|
342
359
|
end
|
343
360
|
|
361
|
+
def replace_worker(job_factory, workers, i, options, blk)
|
362
|
+
# old worker is no longer used ... stop it
|
363
|
+
worker = workers[i]
|
364
|
+
worker.stop if worker
|
365
|
+
|
366
|
+
# create a new replacement worker
|
367
|
+
running = workers - [worker]
|
368
|
+
workers[i] = worker(job_factory, options.merge(started_workers: running), &blk)
|
369
|
+
end
|
370
|
+
|
344
371
|
def create_workers(job_factory, options, &block)
|
345
372
|
workers = []
|
346
373
|
Array.new(options[:count]).each do
|
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.8.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: 2016-03-
|
11
|
+
date: 2016-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|