Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

detached threads still warn

by pryrt (Prior)
on Oct 07, 2016 at 15:36 UTC ( #1173490=perlquestion: print w/replies, xml ) Need Help??

pryrt has asked for the wisdom of the Perl Monks concerning the following question:

So, I started playing around with threads, using Re: buffering zipped pipes as an example. I got something working on my Windows machine, then tried it out on the ancient linux box (perl 5.8.5)... and got the dreaded "A thread exited while 2 threads were running."

I double-checked to make sure that the linux box's perldoc threads claimed support for ->detach, and the WARNINGS section suggested joining to remove the error. I thought ->detach was supposed to make it automatically clean up such stuff.

I tried no warnings 'threads'; or even no warnings;, just to see if I could make the warning go away, but it stuck around.

Given the details (below), how can I get around this warning? Can I install a new local version of threads on the linux machine (I have cpan set up for local library installs), or is threads too core to be able to update with cpan? Or should I just switch to not using ->detach, and do manual cleanup using ->join?

tl;dr details follow...

windows

C:> perl -v | head -2 | tail -1 This is perl 5, version 24, subversion 0 (v5.24.0) built for MSWin32-x +64-multi-thread C:> perl -V | egrep "thread.*=" useithreads=define, usemultiplicity=define C:> perl -Mthreads -le "print $threads::VERSION;" 2.07 C:> perl -Mthreads -le "async { sleep 100; } ; exit;" Perl exited with active threads: 1 running and unjoined 0 finished and unjoined 0 running and detached C:> perl -Mthreads -le "async { sleep 100; }->detach ; exit;" C:>

linux

$ perl -v | head -2 | tail -1 This is perl, v5.8.5 built for i386-linux-thread-multi $ perl -V | egrep 'thread.*=' config_args='-des -Doptimize=-O2 -g -pipe -m32 -march=i386 -mtune= +pentium4 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root@loca +lhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/u +sr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duses +hrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semc +tl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm + -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpage +r=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 +' usethreads=define use5005threads=undef useithreads=define usemulti +plicity=define $ perl -Mthreads -le 'print $threads::VERSION;' 1.05 $ perl -Mthreads -le 'async { sleep 100; } ; exit;' A thread exited while 2 threads were running. $ perl -Mthreads -le 'async { sleep 100; }->detach ; exit;' A thread exited while 2 threads were running. $ perl -Mthreads -le 'no warnings; async { sleep 100; }->detach ; exit +;' A thread exited while 2 threads were running. $

Replies are listed 'Best First'.
Re: detached threads still warn
by hippo (Chancellor) on Oct 07, 2016 at 16:04 UTC
    tried it out on the ancient linux box (perl 5.8.5)...

    how can I get around this warning?

    Upgrade. The version of perl producing the warning is 12 years old which is positively triassic in computing terms. I don't have an installation that old to test it on, but your commands with ->detach work silently on 5.8.8 which is the oldest I have to hand (and is still a decade old).

    $ perl -v This is perl, v5.8.8 built for x86_64-linux-thread-multi Copyright 1987-2006, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. $ perl -Mthreads -le 'async { sleep 100; }->detach ; exit;' $
Re: detached threads still warn
by BrowserUk (Pope) on Oct 07, 2016 at 16:51 UTC
    tried it out on the ancient linux box (perl 5.8.5)... and got the dreaded "A thread exited while 2 threads were running."

    The warning is hardwired and can't be disabled. (I know. I railed, to no avail!) The reason you are seeing it on ancient Perl is because of a bug long since fixed.

    Your choices are upgrade or live with it. It is only a warning.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I was hoping I could do something like installing a local version of threads.pm to distribute with my script... alas.

      Unfortunately, "upgrade perl" is not an option on that family of boxes (they were configured a decade ago for a particular purpose to work in a particular proprietary situation), and any tool I develop for those boxes must work within that framework. If threads ends up improving on my existing script (I don't even know if they will), I'll do a shell wrapper to grep -v that warning away. (My fellow users would complain every time they get a warning using my script.)

      Thanks hippo and BrowserUK... at least I know I'm not just doing something wrong.

        If the warning is meaningless as others have stated, you can catch all warnings by specifying a $SIG{__WARN__} handler, and prevent printing of that specific one:

        use warnings; use strict; $SIG{__WARN__} = sub { my $warn = shift; if ($warn !~ /^A thread exited/){ print $warn; } }; warn "blah blah warning\n"; warn "A thread exited...\n";

        Output:

        blah blah warning

        update: I just realized that the signal handler for warn does not appear to be re-entrant for a warn call from within the handler itself... that is, you can replace my print statement inside the handler with warn, and re-throw the actual warning:

        perl -E '$SIG{__WARN__}=sub{say "handler";warn $_[0] if $_[0]!~/^A thr +ead/}; warn "blah"; warn "A thread";' handler blah at -e line 1. handler

        /update

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1173490]
Approved by Laurent_R
Front-paged by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2020-03-30 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (175 votes). Check out past polls.

    Notices?