Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -X use threads; $thr1 = threads->new(\&manager); while (1){sleep(1);} sub initiator(){ my @in_items = @_; my $torrent = substr(@in_items[0],2); chomp($torrent); my $f = substr(@in_items[1],2); chomp($f); my $lc = substr(@in_items[2],2); chomp($lc); my $priority = substr(@in_items[3],2); chomp($priority); my $buffer = substr(@in_items[4],2); chomp($buffer); my $saveas = substr(@in_items[5],2); chomp($saveas); my $a,$b,$tr_percent,$tr_time,$tr_down,$tr_up,$tr_err,$pid,$urgent +; $final = "downloader.pl $buffer $saveas $priority $f"; $status = open(PIPE,"python btdownloadheadless.py $final |") || pr +int "Couldn't initiate download"; while (<PIPE>){ #print $_; #open(STANDARD, ">>./$buffer/DEBUG.dat"); print STANDARD $_; c +lose(STANDARD); $ln = $_; chomp($ln); ($vb,$vn) = split(/\>\>\>/,$ln); ($a,$b) = split(/---> /,$_); chomp($b); if ($vn ne ""){ $pid = $vn; open(STANDARD2, ">>./$buffer/PID.d +at"); print STANDARD2 "$pid"; close(STANDARD2); } if ($a =~ "percent done"){$tr_percent = $b;} if ($a =~ "time left"){$tr_time = $b;} if ($a =~ "download rate"){$tr_down = $b;} if ($a =~ "upload rate"){$tr_up = $b;} if ($a =~ "ERROR:"){$tr_err = $_; $tr_time = "complete!";} if ($tr_time eq ""){$tr_time = "Connecting...";} open(OUT, ">>./$buffer/WATCH.dat"); print OUT "$tr_time ( % $tr_percent ) \@ $tr_down $tr_err\n"; close(OUT); if (($tr_time =~ "complete!") || ($tr_time eq "Download Succee +ded!")){ sleep(1); print "\nTrying to end process [$buffer] ($pid)...\n"; system("kill -s KILL $pid"); } $v++; } $urgent = 0; open(STANDARD, ">>./$buffer/DEBUG.dat"); print STANDARD "PIPE ENDED..."; $err = $? & 255; print STANDARD "With: $err"; print STANDARD "With: $?"; print STANDARD "With: $status"; close(PIPE); close(STANDARD); undef $a,$b,$tr_percent,$tr_time,$tr_down,$tr_up,$tr_err,$pid,$urg +ent,$v,$err,$vb,$vn,$ln; undef $torrent,$lc,$f,$priority,$buffer,$saveas,$cmd,$cancel; undef @in_items; } sub manager(){ $|++; print "."; opendir(DIR,"./acc"); @list = readdir(DIR); close(DIR); foreach (@list){ if ($_ =~ ".dat"){ @new_list[$q] = $_; $q++; }} #print @new_list; foreach (@new_list){ open(READER,"./acc/$_"); @items = <READER>; close(READER); #print @items; $thr = threads->new(\&initiator, @items); $line = $_; chomp($line); #cp("./acc/$line","./$line/FORKED.dat"); unlink("./acc/$line"); } undef @list; undef @new_list; undef @items; undef $line; $q = 0; sleep(2); &manager(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Oh where has my memory gone?
by BrowserUk (Patriarch) on Jun 09, 2008 at 19:11 UTC | |
|
Re: Oh where has my memory gone?
by radiantmatrix (Parson) on Jun 09, 2008 at 20:27 UTC | |
by shmem (Chancellor) on Jun 09, 2008 at 21:02 UTC | |
by Anonymous Monk on Jun 10, 2008 at 22:06 UTC | |
by Anonymous Monk on Jun 11, 2008 at 02:17 UTC | |
by Anonymous Monk on Jun 09, 2008 at 20:51 UTC | |
|
Re: Oh where has my memory gone?
by Narveson (Chaplain) on Jun 09, 2008 at 19:21 UTC | |
by perrin (Chancellor) on Jun 09, 2008 at 19:50 UTC | |
by Anonymous Monk on Jun 09, 2008 at 19:26 UTC | |
by bart (Canon) on Jun 09, 2008 at 19:43 UTC | |
by massa (Hermit) on Jun 09, 2008 at 19:43 UTC | |
|
Re: Oh where has my memory gone?
by toolic (Bishop) on Jun 09, 2008 at 20:23 UTC | |
|
Re: Oh where has my memory gone?
by perrin (Chancellor) on Jun 09, 2008 at 19:45 UTC | |
by Anonymous Monk on Jun 09, 2008 at 19:49 UTC |