timeout 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d65cc31f39a22fdc316cc89f8f8e4adb95131700972fca8f65cb79ab5c844858
4
- data.tar.gz: 9cb854b05e02484a179c83f56ddb3d85b885806148fd1350223d5406cc20c706
3
+ metadata.gz: 201c519af67a105d6bd6e83e6f983cb7ab41c2968be1433ab9421498a1a1cfc3
4
+ data.tar.gz: 0d9b5e39dda0333010013508b000eb95c584f5959932665b5fa7c3cb23d64112
5
5
  SHA512:
6
- metadata.gz: d88ad9e1965efed376d164a1dd992f3aa423aab9bf3f6c0fdc482affc9895991ff542831ce6d8159771fa000d5e3e5c0679fedbfa73f94fe8c6548fe9f387714
7
- data.tar.gz: '00529ed0c665d1f24c466461ab4c9298d79db2a00f9d12993e1cda402543006f3cf9e88c6f5a36286bef5b97fbaa4f0894cd4b1715b5691bb883bb7e48f37d4f'
6
+ metadata.gz: 754ad7872462dcc555b91c1c589662e3e11f0bdbd2057b336e813e20743bb24e9ac74604c1dafea0159690f9cd480b57039fa878b5d523fb3662499560f99f2a
7
+ data.tar.gz: 17a3815d1a1fd685e2b24a3b41717292b9e6c5e370156d6083788fb4594179a29ec9933df106b955a1bd1cfb479097aac462b161d429b55c4cea240927f62583
data/lib/timeout.rb CHANGED
@@ -23,7 +23,7 @@
23
23
  # Copyright:: (C) 2000 Information-technology Promotion Agency, Japan
24
24
 
25
25
  module Timeout
26
- VERSION = "0.3.0"
26
+ VERSION = "0.3.2"
27
27
 
28
28
  # Raised by Timeout.timeout when the block times out.
29
29
  class Error < RuntimeError
@@ -62,7 +62,7 @@ module Timeout
62
62
 
63
63
  def initialize(thread, timeout, exception_class, message)
64
64
  @thread = thread
65
- @deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
65
+ @deadline = GET_TIME.call(Process::CLOCK_MONOTONIC) + timeout
66
66
  @exception_class = exception_class
67
67
  @message = message
68
68
 
@@ -98,7 +98,7 @@ module Timeout
98
98
  private_constant :Request
99
99
 
100
100
  def self.create_timeout_thread
101
- Thread.new do
101
+ watcher = Thread.new do
102
102
  requests = []
103
103
  while true
104
104
  until QUEUE.empty? and !requests.empty? # wait to have at least one request
@@ -109,7 +109,7 @@ module Timeout
109
109
 
110
110
  now = 0.0
111
111
  QUEUE_MUTEX.synchronize do
112
- while (now = Process.clock_gettime(Process::CLOCK_MONOTONIC)) < closest_deadline and QUEUE.empty?
112
+ while (now = GET_TIME.call(Process::CLOCK_MONOTONIC)) < closest_deadline and QUEUE.empty?
113
113
  CONDVAR.wait(QUEUE_MUTEX, closest_deadline - now)
114
114
  end
115
115
  end
@@ -120,6 +120,10 @@ module Timeout
120
120
  requests.reject!(&:done?)
121
121
  end
122
122
  end
123
+ ThreadGroup::Default.add(watcher) unless watcher.group.enclosed?
124
+ watcher.name = "Timeout stdlib thread"
125
+ watcher.thread_variable_set(:"\0__detached_thread__", true)
126
+ watcher
123
127
  end
124
128
  private_class_method :create_timeout_thread
125
129
 
@@ -132,6 +136,12 @@ module Timeout
132
136
  end
133
137
  end
134
138
  end
139
+
140
+ # We keep a private reference so that time mocking libraries won't break
141
+ # Timeout.
142
+ GET_TIME = Process.method(:clock_gettime)
143
+ private_constant :GET_TIME
144
+
135
145
  # :startdoc:
136
146
 
137
147
  # Perform an operation in a block, raising an error if it takes longer than
data/timeout.gemspec CHANGED
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata["homepage_uri"] = spec.homepage
22
22
  spec.metadata["source_code_uri"] = spec.homepage
23
23
 
24
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
- `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|rakelib)/|\.(?:git|travis|circleci)|appveyor|Rakefile)})
27
+ end
26
28
  end
27
- spec.bindir = "exe"
28
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-25 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Auto-terminate potentially long-running operations in Ruby.
14
14
  email:
@@ -17,15 +17,9 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".github/dependabot.yml"
21
- - ".github/workflows/test.yml"
22
- - ".gitignore"
23
20
  - Gemfile
24
21
  - LICENSE.txt
25
22
  - README.md
26
- - Rakefile
27
- - bin/console
28
- - bin/setup
29
23
  - lib/timeout.rb
30
24
  - timeout.gemspec
31
25
  homepage: https://github.com/ruby/timeout
@@ -50,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
44
  - !ruby/object:Gem::Version
51
45
  version: '0'
52
46
  requirements: []
53
- rubygems_version: 3.3.7
47
+ rubygems_version: 3.5.0.dev
54
48
  signing_key:
55
49
  specification_version: 4
56
50
  summary: Auto-terminate potentially long-running operations in Ruby.
@@ -1,6 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: 'github-actions'
4
- directory: '/'
5
- schedule:
6
- interval: 'weekly'
@@ -1,22 +0,0 @@
1
- name: test
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- ruby: [ '3.0', 2.7, 2.6, 2.5, 2.4, head, jruby, truffleruby-head ]
12
- os: [ ubuntu-latest, macos-latest ]
13
- runs-on: ${{ matrix.os }}
14
- steps:
15
- - uses: actions/checkout@v3
16
- - name: Set up Ruby
17
- uses: ruby/setup-ruby@v1
18
- with:
19
- ruby-version: ${{ matrix.ruby }}
20
- bundler-cache: true # 'bundle install' and cache gems
21
- - name: Run test
22
- run: bundle exec rake test
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
data/Rakefile DELETED
@@ -1,17 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test/lib"
6
- t.ruby_opts << "-rhelper"
7
- t.test_files = FileList["test/**/test_*.rb"]
8
- end
9
-
10
- task :sync_tool do
11
- require 'fileutils'
12
- FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
13
- FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
14
- FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
15
- end
16
-
17
- task :default => :test
data/bin/console DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "timeout"
5
-
6
- require "irb"
7
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install