P is for Practical | |
PerlMonks |
Win32: timing out a perl subroutineby osfameron (Hermit) |
on Jun 19, 2001 at 16:56 UTC ( [id://89618]=perlquestion: print w/replies, xml ) | Need Help?? |
osfameron has asked for the wisdom of the Perl Monks concerning the following question:
Similar topics have already been discussed relating to timing out on Perlmonks processes (e.g. the Net::Ping discussion) and user input (with Term::ReadKey etc.).
The problem is that alarm() is not implemented on Win32 Perl. Possible workarounds are forking off a subprocess (from Perl 5.6 possibled in Win32) and killing it if its still alive after timeout. But I've not come across any discussion (and apologies if I've just missed it) about timing out a Perl sub. That is, I want to get back the result of an arbitrary subrouting call - so I can't fork off a disassociated process. e.g. $result should either return the result of the sub in the code reference, or the value of the 'timed_out' parameter (most likely undef). What I've tried I tried using threads, because I'd understood that this was how Win32 'fork' emulation was done... but I get a "No threads in this Perl" error. (perl -v gives me "v5.6.0 built for MSWin32-x86-multi-thread ... Binary build 616 provided by ActiveState")
I thought of the following:
But I don't think a child can kill the parent?
Alternatively, the child could flag to the parent that it will now take over thank you very much, so that if/when the parent returns it will just exit.
But I'm confused on the details of IPC.
I've read perlipc, and it's very inspiring, but as 60-70% of it is Unix-only, it's a little confusing for us Win32 types. So does anyone have any suggestions, even pointers of where to rtfm?
Cheerio!
Back to
Seekers of Perl Wisdom
|
|