The following code does that.
#! 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.


In reply to Re^2: Interrupting a blocking read (Linux::Inotify2) with a signal handler within a thread by clueless newbie
in thread Interrupting a blocking read (Linux::Inotify2) with a signal handler within a thread by clueless newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.