timeout 0.4.2 → 0.4.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/timeout.rb +8 -3
  3. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9390c49817b43adbd0f8eabd5d93f5535fd01a2d8007c901cdb0a4a85c8702eb
4
- data.tar.gz: a8a0e97bf6a3f61eb0911911b476396b265ee0088aaeecfb136efcfb68799bbf
3
+ metadata.gz: 2e546a82029e45c714f45f0a47cbcb3e747ba7faee26569c1c23126aa15af62f
4
+ data.tar.gz: 3a3b43a30e17b257eb10efbaf542cfa1cba3f2382900c5d84d6fc8ffd48fc053
5
5
  SHA512:
6
- metadata.gz: d0c3e963a4bb920583921a854057fc4c1b0f89d9c7a5a44a27e59455ce74c81e98486f9fe2904124bd25a601ed420f5ec47374ed48480ab97d65f3f837b0549a
7
- data.tar.gz: 23e8bb2e41674a81dcf8440184e66565afdd69b08f0d4402cbc0a27453d2afab9d10bad8905f92aac2be22a41dc20cdcfc70f7f6d87ca6019e8815de57362492
6
+ metadata.gz: aed390b63eb9cbbf06ad8077e107fc8524400102b63bd02615336ecf051e86c35d5258df1e148246c0675c22c84dfc4a652f9b1dffeef79515c011ffec31eb9b
7
+ data.tar.gz: e53db10269c082ff01290139ab63783b1e33e4f2cf29a33ef7741af766256187f54270a16c9f1da84060a4824b5bb723d1822043513a4f7292947588d11f5f99
data/lib/timeout.rb CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  module Timeout
22
22
  # The version
23
- VERSION = "0.4.2"
23
+ VERSION = "0.4.4"
24
24
 
25
25
  # Internal error raised to when a timeout is triggered.
26
26
  class ExitException < Exception
@@ -123,6 +123,9 @@ module Timeout
123
123
 
124
124
  def self.ensure_timeout_thread_created
125
125
  unless @timeout_thread and @timeout_thread.alive?
126
+ # If the Mutex is already owned we are in a signal handler.
127
+ # In that case, just return and let the main thread create the @timeout_thread.
128
+ return if TIMEOUT_THREAD_MUTEX.owned?
126
129
  TIMEOUT_THREAD_MUTEX.synchronize do
127
130
  unless @timeout_thread and @timeout_thread.alive?
128
131
  @timeout_thread = create_timeout_thread
@@ -141,9 +144,10 @@ module Timeout
141
144
  # Perform an operation in a block, raising an error if it takes longer than
142
145
  # +sec+ seconds to complete.
143
146
  #
144
- # +sec+:: Number of seconds to wait for the block to terminate. Any number
145
- # may be used, including Floats to specify fractional seconds. A
147
+ # +sec+:: Number of seconds to wait for the block to terminate. Any non-negative number
148
+ # or nil may be used, including Floats to specify fractional seconds. A
146
149
  # value of 0 or +nil+ will execute the block without any timeout.
150
+ # Any negative number will raise an ArgumentError.
147
151
  # +klass+:: Exception Class to raise if the block fails to terminate
148
152
  # in +sec+ seconds. Omitting will use the default, Timeout::Error
149
153
  # +message+:: Error message to raise with Exception Class.
@@ -165,6 +169,7 @@ module Timeout
165
169
  # a module method, so you can call it directly as Timeout.timeout().
166
170
  def timeout(sec, klass = nil, message = nil, &block) #:yield: +sec+
167
171
  return yield(sec) if sec == nil or sec.zero?
172
+ raise ArgumentError, "Timeout sec must be a non-negative number" if 0 > sec
168
173
 
169
174
  message ||= "execution expired"
170
175
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-06 00:00:00.000000000 Z
10
+ date: 2025-10-29 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Auto-terminate potentially long-running operations in Ruby.
14
13
  email:
@@ -32,7 +31,6 @@ metadata:
32
31
  homepage_uri: https://github.com/ruby/timeout
33
32
  source_code_uri: https://github.com/ruby/timeout
34
33
  changelog_uri: https://github.com/ruby/timeout/releases
35
- post_install_message:
36
34
  rdoc_options: []
37
35
  require_paths:
38
36
  - lib
@@ -47,8 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
45
  - !ruby/object:Gem::Version
48
46
  version: '0'
49
47
  requirements: []
50
- rubygems_version: 3.5.11
51
- signing_key:
48
+ rubygems_version: 3.6.9
52
49
  specification_version: 4
53
50
  summary: Auto-terminate potentially long-running operations in Ruby.
54
51
  test_files: []