extreme_timeout 0.3.0 → 0.3.1
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/ext/extreme_timeout/extreme_timeout.c +15 -5
- data/extreme_timeout.gemspec +1 -1
- data/spec/extreme_timeout_spec.rb +9 -0
- 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: 7754f3b91ffc5530ee342f1ce0bf1656a6849a0d
|
4
|
+
data.tar.gz: 722846c93dd5ccc6f2829cc96d8b3ecfc026455b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c0d7a96b0f5964780b876f7a53f4531cea70e10074a2c493ed48704ddbce3c67240b38c7e1d56d3c6ea2a34e140f5b8ba49cee3a62c04bec4946c61cc6e82bb
|
7
|
+
data.tar.gz: f79640ff7b1455e7d4f10b5a482e147ad006b35877f41428bf7d637511c4c6307ca3195c7f6cb9d4a1da862c37209f376d6a938fe50cdad08489dff80e7c317d
|
@@ -65,17 +65,27 @@ sleep_thread_main(void *_arg)
|
|
65
65
|
|
66
66
|
pthread_mutex_lock(&exitcode_mutex);
|
67
67
|
exitcode = arg->exitcode;
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
if (!rb_during_gc()) {
|
69
|
+
set_stacktrace_dumper();
|
70
|
+
if (pthread_kill(arg->running_thread, SIGCONT) == 0) {
|
71
|
+
pthread_join(arg->running_thread, NULL);
|
72
|
+
}
|
73
|
+
} else {
|
74
|
+
exit(exitcode);
|
71
75
|
}
|
72
76
|
return NULL;
|
73
77
|
}
|
74
78
|
|
79
|
+
static VALUE
|
80
|
+
timeout_cb(VALUE block)
|
81
|
+
{
|
82
|
+
return rb_funcall(block, rb_intern("call"), 0);
|
83
|
+
}
|
84
|
+
|
75
85
|
VALUE
|
76
86
|
timeout(int argc, VALUE *argv, VALUE self)
|
77
87
|
{
|
78
|
-
int exitcode = 1;
|
88
|
+
int exitcode = 1, state;
|
79
89
|
unsigned int timeout_sec = 0;
|
80
90
|
VALUE timeout_sec_value, exitcode_value, block;
|
81
91
|
pthread_t thread;
|
@@ -108,7 +118,7 @@ timeout(int argc, VALUE *argv, VALUE self)
|
|
108
118
|
rb_raise(rb_eRuntimeError, "pthread_create was failed");
|
109
119
|
}
|
110
120
|
|
111
|
-
retval =
|
121
|
+
retval = rb_protect(timeout_cb, block, &state);
|
112
122
|
|
113
123
|
pthread_cancel(thread);
|
114
124
|
pthread_join(thread, NULL);
|
data/extreme_timeout.gemspec
CHANGED
@@ -73,5 +73,14 @@ describe ExtremeTimeout do
|
|
73
73
|
expect(stderr.read).to start_with("Process exits(ExtremeTimeout::timeout)\n")
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
it 'discards timeout if an exception was raised' do
|
78
|
+
begin
|
79
|
+
ExtremeTimeout::timeout(1) { raise Exception.new }
|
80
|
+
fail 'An exception should be raised'
|
81
|
+
rescue Exception
|
82
|
+
sleep(5)
|
83
|
+
end
|
84
|
+
end
|
76
85
|
end
|
77
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extreme_timeout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaya SUZUKI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|