From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.5 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 922051F6A9 for ; Sat, 5 Jan 2019 20:42:26 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 7F8B31212C5; Sun, 6 Jan 2019 05:42:23 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 28A241211EF for ; Sun, 6 Jan 2019 05:42:20 +0900 (JST) Received: by filter0051p3iad2.sendgrid.net with SMTP id filter0051p3iad2-24011-5C3116A5-1C 2019-01-05 20:42:13.468455592 +0000 UTC m=+156799.533572247 Received: from herokuapp.com (ec2-54-211-178-201.compute-1.amazonaws.com [54.211.178.201]) by ismtpd0050p1mdw1.sendgrid.net (SG) with ESMTP id me5fqMGrRXGfViuo0Zs8kg for ; Sat, 05 Jan 2019 20:42:13.389 +0000 (UTC) Date: Sat, 05 Jan 2019 20:42:15 +0000 (UTC) From: lars@greiz-reinsdorf.de To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66324 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15510 X-Redmine-Issue-Author: larskanis X-Redmine-Sender: larskanis X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4E8kWOoZ8eY2b9LYvH1SzJvNey8R3jjHomPe Lik47KyTVgpolpKUZdPtL0WxFSN1vyfqC3GT8cj9ponOY+I8xzTNhHGytaemvfBe8FShPKvlDo2rP8 AW7OKwCzTtKHfoPtjOa+yAk9y5UAd/gKua1Kok/LdqhxPiSDcT/duW7MnA== X-ML-Name: ruby-core X-Mail-Count: 90903 Subject: [ruby-core:90903] [Ruby trunk Misc#15510] Easter egg in Thread.handle_interrupt X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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/