Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Setting Timeout in Image::Grab??

by dazz (Beadle)
on Mar 26, 2017 at 19:35 UTC ( [id://1186001]=perlquestion: print w/replies, xml ) Need Help??

dazz has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I am using Image::Grab to gr1ab images off an IP Camera. That is all working OK.

The problem I have is that the timeout for a bad connection is 3minutes but I expect to be grabbing images every 60 seconds. If there is a problem with the camera, I will end up with multiple threads running waiting for an image. I have looked at the documentation here http://search.cpan.org/~mahex/Image-Grab-1.4.2/lib/Image/Grab.pod

I need to change the value of Timeout.

My code looks like this:

#get the latest image from the IP camera my $snapshot = new Image::Grab; $snapshot->timeout(5); #sets the timeout (sec) for image::grab (defau +lt is 180s) $snapshot->url("$Camera{$key}"); # create the grab object $snapshot->grab; # grab the image open (IMAGE, ">$lastsnap{$key}") || die syslog(LOG_ERR, "Couldn't ope +n file, $!"); # opens and clears th$ binmode IMAGE; # for MSDOS derivations. print IMAGE $snapshot->image; # save the image to the /var/images/Tra +ckcam folder close IMAGE or die $!;
Perl debugger spits out the following error message:
Can't access `timeout' field in class Image::Grab at upload-images.pl +line 79. at /usr/local/share/perl/5.18.2/Image/Grab.pm line 81. Image::Grab::AUTOLOAD('Image::Grab=HASH(0x8698344)', 5) called + at upload-images.pl line 79

My question is how do I change the Timeout property to 5sec?

Replies are listed 'Best First'.
Re: Setting Timeout in Image::Grab??
by dazz (Beadle) on Mar 26, 2017 at 19:41 UTC
    Hi I figured it out:
    $snapshot->ua->timeout(5);
    ua is the container that holds the timeout property.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1186001]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-28 16:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found