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.0 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 6F03A211B4 for ; Sat, 5 Jan 2019 23:53:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id BE104121383; Sun, 6 Jan 2019 08:53:53 +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 3EBF6121274 for ; Sun, 6 Jan 2019 08:53:51 +0900 (JST) Received: by filter0061p3iad2.sendgrid.net with SMTP id filter0061p3iad2-10352-5C31438B-11 2019-01-05 23:53:47.411832387 +0000 UTC m=+168541.422434310 Received: from herokuapp.com (ec2-54-167-255-53.compute-1.amazonaws.com [54.167.255.53]) by ismtpd0019p1iad2.sendgrid.net (SG) with ESMTP id owA3_MEXTIa_htz9M38M9w for ; Sat, 05 Jan 2019 23:53:47.304 +0000 (UTC) Date: Sat, 05 Jan 2019 23:53:48 +0000 (UTC) From: eregontp@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66328 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15510 X-Redmine-Issue-Author: larskanis X-Redmine-Sender: Eregon 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5yjWjvoycBcmhuLyBlNhwVepp+wsGT0EqRGp qK2M9OOyrPRWz8biuWX+6Hric8uajmiXz/zZwhPe/QLkwb9Qjskz5nmaG4WrmXMk/lTzvtNTUm2HGX 8EcAYJw5ylz2QfQRvnI/PcYtbOtVy3Bw/5PpsVBp0nnhYE9iQHp+830MwQ== X-ML-Name: ruby-core X-Mail-Count: 90907 Subject: [ruby-core:90907] [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 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/