parallel 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e98f73ce25c329aab14185e79d68643dde8b705
4
- data.tar.gz: bcf7f3490b62a267b9c54b82114c25193fdef811
3
+ metadata.gz: 11290960cd496e43b8e7c9314769ffc8a3554daa
4
+ data.tar.gz: bfc4d8c942312266e0fbe3ebc66f0fd19923fffe
5
5
  SHA512:
6
- metadata.gz: 6209b06e7fd1a09a92c1e485c156b4abc57ba5c230f21ae6d7df5752d06acaf2adc55771230bda207a37a770b0a3241cad33e0d27da125ed1c8642c848f16633
7
- data.tar.gz: 6e08572a7a48ce2d5da1e325c02ab701297854fd5e22397835e48d361f86968a79fb764a5c2df91f4cfbf81ff31d9f5bb3ed39ed86f570ffc075c29084fb049f
6
+ metadata.gz: 90cd2a5f9af376e208f64483b416ea23cb92de3ac03eb8c5fbb2cf86576717d846dfaa8a3d0dd8a183a4543c855b81978829b09325e7b0e7f32283b8ff69dcfa
7
+ data.tar.gz: 066e43a835be012a025536bbfcf0f2ff7ed8bd50a9295d760b44b3f10492be3496e36154ff816717126dd0dd3b53cd1152340b01db025b60e46a30609a65e9d3
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/parallel.rb CHANGED
@@ -12,6 +12,8 @@ module Parallel
12
12
  class Kill < StandardError
13
13
  end
14
14
 
15
+ INTERRUPT_SIGNAL = :SIGINT
16
+
15
17
  class ExceptionWrapper
16
18
  attr_reader :exception
17
19
  def initialize(exception)
@@ -360,21 +362,41 @@ module Parallel
360
362
 
361
363
  # kill all these pids or threads if user presses Ctrl+c
362
364
  def kill_on_ctrl_c(things)
363
- if defined?(@to_be_killed) && @to_be_killed
364
- @to_be_killed << things
365
- else
366
- @to_be_killed = [things]
367
- Signal.trap :SIGINT do
368
- if @to_be_killed.any?
369
- $stderr.puts 'Parallel execution interrupted, exiting ...'
370
- @to_be_killed.flatten.compact.each { |thing| kill_that_thing!(thing) }
371
- end
372
- exit 1 # Quit with 'failed' signal
365
+ @to_be_killed ||= []
366
+ old_interrupt = nil
367
+
368
+ if @to_be_killed.empty?
369
+ old_interrupt = trap_interrupt do
370
+ $stderr.puts 'Parallel execution interrupted, exiting ...'
371
+ @to_be_killed.flatten.compact.each { |thing| kill_that_thing!(thing) }
373
372
  end
374
373
  end
374
+
375
+ @to_be_killed << things
376
+
375
377
  yield
376
378
  ensure
377
379
  @to_be_killed.pop # free threads for GC and do not kill pids that could be used for new processes
380
+ restore_interrupt(old_interrupt) if @to_be_killed.empty?
381
+ end
382
+
383
+ def trap_interrupt
384
+ old = Signal.trap INTERRUPT_SIGNAL, 'IGNORE'
385
+
386
+ Signal.trap INTERRUPT_SIGNAL do
387
+ yield
388
+ if old == "DEFAULT"
389
+ raise Interrupt
390
+ else
391
+ old.call
392
+ end
393
+ end
394
+
395
+ old
396
+ end
397
+
398
+ def restore_interrupt(old)
399
+ Signal.trap INTERRUPT_SIGNAL, old
378
400
  end
379
401
 
380
402
  def kill_that_thing!(thing)
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '1.1.2'
2
+ VERSION = Version = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -30,7 +30,7 @@ cert_chain:
30
30
  F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
31
31
  /0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
32
32
  -----END CERTIFICATE-----
33
- date: 2014-07-18 00:00:00.000000000 Z
33
+ date: 2014-08-07 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description:
36
36
  email: michael@grosser.it
metadata.gz.sig CHANGED
Binary file