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

Hello great Monks!
I'd like to print something on the screen while doing a big file copy operation.Let's say I want print "#" each second untill the copy operation ends.
I've decided to try Thread module and it works,however every time upon exit I get an error:
A thread exited while 2 threads were running
I know that I have to collect the child thread before joining the master,but since I wish the printing to be done as long as the copying is running -it's kind of hard.
Is there a way to suppress this annoying error message or is there any other suggestion?
Thank you very much in advance!

Replies are listed 'Best First'.
Re: print # while doing file copy
by Hue-Bond (Priest) on Dec 19, 2005 at 16:37 UTC

    You could use alarm and the proper signal handler.

    $SIG{ALRM} = sub { print "got signal, bye bye!\n"; exit 0; }; alarm 2; sleep 10; __END__ got signal, bye bye!

    --
    David Serrano

Re: print # while doing file copy
by Fletch (Bishop) on Dec 19, 2005 at 16:35 UTC

    Well, judging by the code you've posted showing what's causing the error . . . erm *cough* . . .

    Must be the vreemflitzer. Try re-coating it with 23 to 42 mils of unobtanium and run again.

    Yeah, that's the ticket.

Re: print # while doing file copy
by zentara (Cardinal) on Dec 20, 2005 at 12:25 UTC
    The error "A thread exited while 2 threads were running" can be fixed by making sure your threads return( or go to the end of their code block),and be joined, before you exit. This can be done with a shared variable, but you must show your code example.

    Also, it is supposedly a harmless warning, maybe we need a way to set "no warnings threads" in scripts?


    I'm not really a human, but I play one on earth. flash japh