in reply to Re: Interrupting a blocking read (Linux::Inotify2) with a signal handler within a thread
in thread Interrupting a blocking read (Linux::Inotify2) with a signal handler within a thread
#! use Cwd; use Data::Dumper; use Linux::Inotify2; use strict; use warnings; my $Inotify_o=Linux::Inotify2->new(); $Inotify_o->watch(Cwd::abs_path('.'),IN_ALL_EVENTS); $|++; my $Done_f; # Ctrl/c signal handler --- works! $SIG{INT}=$SIG{TERM}=$SIG{HUP}= sub { # ? print "SignalHandler tripped!\n"; $Done_f=1; print "Attempting to unblock Inotify\n"; $Inotify_o->blocking(0); print "Inotify unblocked!\n" }; # SignalHandler: Done print "Starting while.\n"; while (!$Done_f) { print "Waiting on read.\n"; my @events_ao = $Inotify_o->read; print "read has been unblocked.\n"; unless (@events_ao > 0){ print "read error: $!\n"; } else { # To Do! foreach my $event_o (@events_ao) { print $event_o->fullname . " was modified\n" if $event_o->IN_M +ODIFY; if ($event_o->fullname =~ m{\.pm$} && $event_o->IN_CLOSE_W +RITE) { # Have a module } elsif ($event_o->fullname =~ m{\.(?:cgi|pl)$} && $event_o- +>IN_CLOSE_WRITE) { # Have a script }; }; }; print "Continuing while.\n"; }; print "Exiting!\n"; __END__
Which yields
perl sighandler.pl Starting while. Waiting on read. ^CSignalHandler tripped! Attempting to unblock Inotify Inotify unblocked! read has been unblocked. read error: Interrupted system call Continuing while. Exiting!
That leads me to believe that if all else fails I can "invert" it and have the main do the watching/work submittal and have the worker perform the submitted work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Interrupting a blocking read (Linux::Inotify2) with a signal handler within a thread
by BrowserUk (Patriarch) on Sep 10, 2011 at 20:24 UTC | |
by clueless newbie (Curate) on Sep 10, 2011 at 20:40 UTC | |
by BrowserUk (Patriarch) on Sep 10, 2011 at 20:53 UTC | |
by clueless newbie (Curate) on Sep 10, 2011 at 21:03 UTC |