DCPM: Timeouts in modules

Neil Williams linux at codehelp.co.uk
Sun Nov 30 10:13:40 CST 2003


On Sunday 30 Nov 2003 3:06 pm, Matthew Browning wrote:
> On Sunday 30 November 2003 13:22, Neil Williams wrote:
> > In PHP there's an easy config setting that changes the timeout per
> > script or per installation...
>
> In IO::Socket there is a timeout method but presumably your process is
> instantiated by some module up the hierarchy.

Correct, I can't use the IO::Socket method.

> You could take a look at this (source is nothing to do with me and I do
> not approve of it):
>
> http://www.foo.be/docs/perl/advprog/ch05_06.htm

The official perldoc does have a similar example.
http://www.perldoc.com/perl5.8.0/pod/perlipc.html#Signals

I can't get it to work. When I use alarm 5; I can get the script to terminate 
with Alarm clock but I can't handle $SIG{ALRM} - the alarm is suddenly and 
completely ignored!

	eval{
		local $SIG{ALRM} = sub{ die "my own alarm" };
		alarm 5;
		$conn = $mgr->connect("$server", "$port");
		alarm 0;
	};

my own alarm is never shown, the timeout is ignored and the script just 
continues waiting for nothing.

If I comment out the local ALRM handler, the script ends with Alarm clock - I 
want the script to continue with the error being logged!

The main die() handler is not getting in the way because I can remove it and 
still the alarm will not work if $SIG{ALRM} is used but it will halt the 
script completely if it is not.

This needs to be called from within a for() loop - does that make a 
difference?

I've tried with the 
		local $SIG{ALRM} = sub{ die "my own alarm" };
line inside and outside the loop, inside or outside the eval{};

Incidentally, why must the eval have }; at the end instead of just }
?

-- 

Neil Williams
=============
http://www.codehelp.co.uk/
http://www.dclug.org.uk/
http://www.isbn.org.uk/
http://sourceforge.net/projects/isbnsearch/

http://www.biglumber.com/x/web?qs=0x8801094A28BCB3E3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url : http://mail.pm.org/archives/devoncornwall-pm/attachments/20031130/b27fc63d/attachment.bin


More information about the Devoncornwall-pm mailing list