ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:90903] [Ruby trunk Misc#15510] Easter egg in Thread.handle_interrupt
       [not found] <redmine.issue-15510.20190105204212@ruby-lang.org>
@ 2019-01-05 20:42 ` lars
  2019-01-05 23:53 ` [ruby-core:90907] " eregontp
  1 sibling, 0 replies; 2+ messages in thread
From: lars @ 2019-01-05 20:42 UTC (permalink / raw)
  To: ruby-core

Issue #15510 has been reported by larskanis (Lars Kanis).

----------------------------------------
Misc #15510: Easter egg in Thread.handle_interrupt
https://bugs.ruby-lang.org/issues/15510

* Author: larskanis (Lars Kanis)
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
The docs of `Thread.handle_interrupt` are quite clear about the argument to be passed. It must be a hash of `ExceptionClass => :TimingSymbol` pairs. I never thought that anything other than a `Exception` derivation would be accepted.

But then I read the tests to this method and wondered: [Some of the tests](https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L783) set `Object` as `ExceptionClass`. Moreover the method is not covered by ruby-spec and JRuby [excludes several failing tests](https://github.com/jruby/jruby/blob/66d2905ae233a39e36fcbe3ade6382c2892ade8e/test/mri/excludes/TestThread.rb).

So I inspected the code and found some obscure behavior: There are actually [two non-exceptions](https://github.com/ruby/ruby/blob/trunk/thread.c#L115-L116) which can be masked by `Thread.handle_interrupt(Integer => :TimingSymbol)`. It is main thread termination and `Thread#kill`. Now this [blur sentence in the docs](https://github.com/ruby/ruby/blob/trunk/thread.c#L1891-L1894) makes some more sense:

> interrupt means asynchronous event and corresponding procedure by Thread#raise, Thread#kill, signal trap (not supported yet) and main thread termination (if main thread terminates, then all other thread will be killed).

So they are implemented as integers internally. However IMHO `Thread.handle_interrupt(Integer => :TimingSymbol)` is ... ugly.

Some proposals are:
1. Make non-exceptions an ruby implementation specific feature, adjusts current tests and optionally add tests which are tagged as implementation specific.
2. Document it officially, but choose some more meaningful class names instead of `Integer`




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:90907] [Ruby trunk Misc#15510] Easter egg in Thread.handle_interrupt
       [not found] <redmine.issue-15510.20190105204212@ruby-lang.org>
  2019-01-05 20:42 ` [ruby-core:90903] [Ruby trunk Misc#15510] Easter egg in Thread.handle_interrupt lars
@ 2019-01-05 23:53 ` eregontp
  1 sibling, 0 replies; 2+ messages in thread
From: eregontp @ 2019-01-05 23:53 UTC (permalink / raw)
  To: ruby-core

Issue #15510 has been updated by Eregon (Benoit Daloze).


`Integer` sure feels like a hack, but using `Thread.handle_interrupt(Object => :TimingSymbol)` makes some sense, and I think we should document that as a way to also ignore those interrupts.

I'm against 1) (no need to be implementation-specific here), and I think 2) with `Object` or a variant (e.g., a Symbol :all) would be good.

Specs for Thread.handle_interrupt would be nice to have in ruby/spec, contributions welcome!

----------------------------------------
Misc #15510: Easter egg in Thread.handle_interrupt
https://bugs.ruby-lang.org/issues/15510#change-76087

* Author: larskanis (Lars Kanis)
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
The docs of `Thread.handle_interrupt` are quite clear about the argument to be passed. It must be a hash of `ExceptionClass => :TimingSymbol` pairs. I never thought that anything other than a `Exception` derivation would be accepted.

But then I read the tests to this method and wondered: [Some of the tests](https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L783) set `Object` as `ExceptionClass`. Moreover the method is not covered by ruby-spec and JRuby [excludes several failing tests](https://github.com/jruby/jruby/blob/66d2905ae233a39e36fcbe3ade6382c2892ade8e/test/mri/excludes/TestThread.rb).

So I inspected the code and found some obscure behavior: There are actually [two non-exceptions](https://github.com/ruby/ruby/blob/trunk/thread.c#L115-L116) which can be masked by `Thread.handle_interrupt(Integer => :TimingSymbol)`. It is main thread termination and `Thread#kill`. Now this [blur sentence in the docs](https://github.com/ruby/ruby/blob/trunk/thread.c#L1891-L1894) makes some more sense:

> interrupt means asynchronous event and corresponding procedure by Thread#raise, Thread#kill, signal trap (not supported yet) and main thread termination (if main thread terminates, then all other thread will be killed).

So they are implemented as integers internally. However IMHO `Thread.handle_interrupt(Integer => :TimingSymbol)` is ... ugly.

Some proposals are:
1. Make non-exceptions an ruby implementation specific feature, adjusts current tests and optionally add tests which are tagged as implementation specific.
2. Document it officially, but choose some more meaningful class names instead of `Integer`




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-05 23:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15510.20190105204212@ruby-lang.org>
2019-01-05 20:42 ` [ruby-core:90903] [Ruby trunk Misc#15510] Easter egg in Thread.handle_interrupt lars
2019-01-05 23:53 ` [ruby-core:90907] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).