CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: calling process in threads with IO: Edit Log



Xhonzi
New User

Oct 24, 2011, 5:31 AM


Views: 9755
calling process in threads with IO

Hello,
I have found that once I call external processes (which generates files) from plenty of threads, sometimes file handles aren't closed and fail on opening or on unlinking of these files. It's very random problem and occurs only e.g. 0-3 times for 200 repeats. But I've tried Win32::Job and for it seems count of these problems increases. I don't know where's the problem:

1) antivirus realtime scan - I have no oportunity to disable it so I can't be sure this is not the reason. But if it's processed only in one thread I've not encountered this problem.
2) I had been searching internet if there's no problem with IO requests when comes from 2 threads in same time if one doesn't block the other, but found no solution.

Have you ever faced such problem once anyone?

Thank you in advance.

#runProcXtimes.pl
use warnings;
use strict;
use threads;
use PROCmod;

foreach my $i(1..200){
map {threads->create(\&subT)} 1..10
sub subT{
PROCmod::run();
}
foreach(threads->list){
while(!$_->is_joinable){;}
$_->join;
}
}

#PROCmod.pm
package PROCmod;

sub run{
my $tID=threads->self->tid;

system("perl -e \"print STDOUT 'stdout';print STDERR 'stderr';\" >o\\stdout_$tID 2>o\\stderr_$tID")==0 or die "$tID:$!";
open(my $SO,'<',"o\\stdout_$tID") or die "open o\\stdout_$tID:$!";
close $SO;
unlink "o\\stdout_$tID" or die "unlink o\\stdout_$tID:$!";
open(my $SE,'<',"o\\stderr_$tID") or die "open o\\stderr_$tID:$!";
close $SE;
unlink "o\\stderr_$tID" or die "unlink o\\stderr_$tID:$!";
}
1;


(This post was edited by Xhonzi on Oct 24, 2011, 5:59 AM)


Edit Log:
Post edited by Xhonzi (New User) on Oct 24, 2011, 5:59 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives