Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Blocking call with time limit ( Linux::Inotify2 )

by BrowserUk (Patriarch)
on Sep 08, 2010 at 09:03 UTC ( [id://859291]=note: print w/replies, xml ) Need Help??


in reply to Blocking call with time limit ( Linux::Inotify2 )

The simple solution is Time::HiRes:

use Time::HiRes qw[ time sleep ]; ... $inotify->blocking(0); my $end = time() + $timelimit; while( time() < $end ) { for my $event ( $inotify->read ) { ## process event. } sleep 0.01; ## or 0.001 per your latency requirements }

As for your fears about cpu usage. Polling once every hundredth or thousandth of a second, (much less every second), barely raises the usage at all. On my system, the usage is not discernible from zero to 2 decimal places.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2024-04-18 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found