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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76d98ba4c245814afabec6e1f5fc5a23d3eee686
4
- data.tar.gz: 4ce0b834aa9ee9bf52cc087208850cda2a3bee85
3
+ metadata.gz: 7754f3b91ffc5530ee342f1ce0bf1656a6849a0d
4
+ data.tar.gz: 722846c93dd5ccc6f2829cc96d8b3ecfc026455b
5
5
  SHA512:
6
- metadata.gz: 7545df380d0d7c3f41b367e4f0019e8f3b224ddae253c6b7158029f61a8e4c336184873038bfdac71d4b15266ca4b7daa10c7ce3c39dbf084b078a9ee9714976
7
- data.tar.gz: 31f5f53757e9b8b5129f41ca60f222d1db8b437be343113172bd1b64e137c878947e7cc73924068fa49cd3a5e8c11c87081422a5bf14b29b1dfbd4cd685c6827
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
- set_stacktrace_dumper();
69
- if (pthread_kill(arg->running_thread, SIGCONT) == 0) {
70
- pthread_join(arg->running_thread, NULL);
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 = rb_funcall(block, rb_intern("call"), 0);
121
+ retval = rb_protect(timeout_cb, block, &state);
112
122
 
113
123
  pthread_cancel(thread);
114
124
  pthread_join(thread, NULL);
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "extreme_timeout"
4
- spec.version = "0.3.0"
4
+ spec.version = "0.3.1"
5
5
  spec.authors = ["Masaya SUZUKI"]
6
6
  spec.email = ["draftcode@gmail.com"]
7
7
  spec.description = "Timeout from the outside of the GVL"
@@ -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.0
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: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler