Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

alarm in DBI module

by vetrivel (Sexton)
on Aug 31, 2010 at 11:09 UTC ( #858153=perlquestion: print w/replies, xml ) Need Help??
vetrivel has asked for the wisdom of the Perl Monks concerning the following question:

Hai , I am using DBI module to connect with postgres data base .

$SIG{ALRM} = sub { print "Alarm Captured" ; exit ; } ; alarm 10 ; DBI->connect(...) alarm 0 ;

My postgresql server is down . If I run the above code , DBI gives me an error after 20 seconds . In this case , Alarm is not captured . But I required alarm should be executecd . Is alarm useful only for IO Interuppt?

Replies are listed 'Best First'.
Re: alarm in DBI module
by salva (Abbot) on Aug 31, 2010 at 11:54 UTC
    As the postgres client library allows to set a timeout for the connecting stage, the implementation of that feature may interfere with any timer previously set from the caller code.

    You can change the default timeout (15s) on the DBI connection string as follows:

    my $dbh = DBI->connect("dbi:Pg:dbname=$db_name;host=$db_host;connect_t +imeout=$db_connect_timeout", ...);
Re: alarm in DBI module
by jethro (Monsignor) on Aug 31, 2010 at 12:10 UTC
    Please don't use <pre> tags for code, they don't wrap text. Use <code> tags instead. With 23 posts published you already should know that. See Writeup Formatting Tips
Re: alarm in DBI module
by vek (Prior) on Aug 31, 2010 at 19:53 UTC

    I absolutely cannot recommend Sys::SigAction enough. I use it successfully in production with MySQL. Go give it a try and let us know if you're still having issues. I suspect you won't.

Re: alarm in DBI module
by mje (Curate) on Sep 08, 2010 at 16:08 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://858153]
Approved by salva
help
Chatterbox?
[Corion]: Hi marto!
[Corion]: I hope you had a good weekend!
[Discipulus]: good morning again monks!
[choroba]: Good morning!
[Corion]: I have a rough plan to release an ImageNet classifier in Perl (well, using pretrained data, but still a nice toy)
Discipulus is going mad with the new win10 client.. tried mv Cortana /dev/null but no succes
[Corion]: Ouch - another pretrained set is available, using images from IMDB and Wikipedia. So I expect interesting results for non-PR images where people are pictured that are not made up
[Corion]: Discipulus: Yeah, from my investigations, you can somewhat silence+disable Cortana, but some services of it remain always running unfortunately. What a waste of resources :-/
[Corion]: I hope you had a good weekend still ;)

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2017-09-25 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (277 votes). Check out past polls.

    Notices?