markperlb0y has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
So I found out that Win32::Ole and threads don't go well together, and Alarms are difficult to get working on Win32.
I need to time user's input and feed the next instructions with some default values when no input is received in STDIN within a given period. If I call read_excel directly, it will work just fine. If i will call it within a thread, then I will still have to press enter before the script can continue executing. But I need to do it this way, otherwise I'll have another problem with Win32::OLE and threads being not compatible (i.e., the program crashes).
I swear I made this work before but when it was time to clean up my code and re-arrange everything, it stopped working. And I couldn't CTRL+Z anymore in Padre because I already closed the file.
I'm on Windows 7, perl 5.14.2 if that helps.
use 5.014; use threads; use threads::shared; my $input : shared; my $inthread = threads->new (sub { $SIG{KILL} = sub { threads->exit(); }; print "Enter something: "; chomp ($input = <STDIN>); }); sleep 5; if (not defined $input) { $inthread->kill('KILL')->detach; } else { print "we got $input!"; } my $message = 'HELLO FROM SUB!!!\n'; my ($excelthread) = threads->create('read_excel', $message); #read_excel($message); say "\nNEW THREAD SUCCESSFULLY CREATED"; sub read_excel{ say shift; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Timed STDIN input via threads on Win32
by kschwab (Vicar) on Nov 19, 2013 at 02:38 UTC | |
by markperlb0y (Initiate) on Nov 19, 2013 at 02:55 UTC | |
by kschwab (Vicar) on Nov 19, 2013 at 03:12 UTC | |
by markperlb0y (Initiate) on Nov 19, 2013 at 03:22 UTC | |
by dasgar (Priest) on Nov 19, 2013 at 04:24 UTC | |
| |
by kschwab (Vicar) on Nov 19, 2013 at 03:45 UTC |