]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ProcessPipe.pm
ds: use WNOHANG with waitpid if inside event loop
[public-inbox.git] / lib / PublicInbox / ProcessPipe.pm
index 2769e064ca21d1651fbace905a167ba17922802b..4f5fc7515c33f91d44e0122d4487fff99dbac6ce 100644 (file)
@@ -20,8 +20,13 @@ sub CLOSE {
        my $ret = defined $fh ? close($fh) : '';
        my $pid = delete $_[0]->{pid};
        if (defined $pid) {
-               waitpid($pid, 0);
-               $ret = '' if $?;
+               # PublicInbox::DS may not be loaded
+               eval { PublicInbox::DS::dwaitpid($pid, undef, undef) };
+
+               if ($@) { # ok, not in the event loop, work synchronously
+                       waitpid($pid, 0);
+                       $ret = '' if $?;
+               }
        }
        $ret;
 }