heiermann has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am back again with another "funny" behaviour of ActivePerl. I am using v5.12.2 on Windows 2008 SP1.
I want to read from a long-running co-process, and I want to be able to interrupt that procedure. In the meantime I want to calculate something asyncronously in a thread, but this thread should not be interruptible to join it in the end.
This code crashes my Perl interpreter:
#! /usr/bin/perl -w use strict; use threads; # Starting a co-process to read from. my $procid = open(READ, '-|', 'perl -e "$|=1; $SIG{INT} = \'IGNORE\'; +for ($i=0;$i<10;$i++) {print \"Line $i\n\"; sleep 1;}"'); my $break = 0; $SIG{INT} = sub { $break=1; }; sub calculation { local $SIG{INT} = 'IGNORE'; print("calculating somet +hing\n"); 5; } my $thread = async(\&calculation); # Reading from co-process. until ($break) { my $line = <READ>; last unless defined $line; print $line; } if ($break) { kill('ABRT', $procid); } close(READ); print $thread->join() ."\n";
Earlier you gave me the advice, not to use signals on Windows heavily, because they cannot be expected to work in all situations.
However, I think it is unbelievable that correct code can crash the interpreter. And, btw, the code is working properly whithout the thread. Can anybody explain?
----------
Thanks for your helping answers. I think BrowserUk gave the correct hint.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Correct code crashes ActivePerl Interpreter (perlbug)
by BrowserUk (Patriarch) on Jan 17, 2011 at 22:26 UTC | |
|
Re: Correct code crashes ActivePerl Interpreter
by BrowserUk (Patriarch) on Jan 17, 2011 at 23:12 UTC | |
|
Re: Correct code crashes ActivePerl Interpreter
by ww (Archbishop) on Jan 17, 2011 at 22:09 UTC | |
|
Re: Correct code crashes ActivePerl Interpreter
by ikegami (Patriarch) on Jan 17, 2011 at 21:27 UTC | |
|
Re: Correct code crashes ActivePerl Interpreter
by Anonyrnous Monk (Hermit) on Jan 17, 2011 at 21:26 UTC | |
|
Re: Correct code crashes ActivePerl Interpreter
by ikegami (Patriarch) on Jan 17, 2011 at 21:32 UTC | |
|
Re: Correct code crashes ActivePerl Interpreter
by afoken (Chancellor) on Jan 17, 2011 at 22:32 UTC | |
by BrowserUk (Patriarch) on Jan 17, 2011 at 22:34 UTC |