in reply to Race condition in Linux::Inotify2 between dir and new file?

Given that your issue is XML::LibXML is trying to read an empty file, perhaps you could use -s to test for non-zero size, and institute a waiting loop until it passes that condition? Something like:

sub process_drop_file { my $file = Path::Class::File->new(shift); -f $file or croak "'$file' is not a file"; sleep(1) until (-s $file); # <-- New line my $doc = XML::LibXML->new->parse_file("$file"); # Do stuff with it... $file->remove or croak "Couldn't remove '$file'"; }

Replies are listed 'Best First'.
Re^2: Race condition in Linux::Inotify2 between dir and new file?
by Your Mother (Archbishop) on Jun 24, 2009 at 23:02 UTC

    I am still hoping there is an event or setting solution but if not the -s check is probably a good approach and I may do just that (with a max_check saftey valve or something in case a real 0 size file comes through). Thanks.

Re^2: Race condition in Linux::Inotify2 between dir and new file?
by spx2 (Deacon) on Jun 25, 2009 at 09:29 UTC
    what if in that second those seconds that you're sleeping waiting for the size of the file to grow, some other files are created in the directory watched ?
    will Iotify2 call process_drop_file for those also ?
    maybe starting 2 threads , one which puts them in a queue and the other which reads them from a queue would be more appropriate to not skip(unintentionally) any of them