Xenofur has asked for the wisdom of the Perl Monks concerning the following question:
use IPC::Open2; for my $id (@ids) { $wgets++; push @pids, open2(undef, undef, 'wget', $url.$id, '-q', '-O', +$dir.$id); while ( @pids >= 10 ) { waitpid( shift @pids, 0 ); } } while ( @pids ) { waitpid( shift @pids, 0 ); }
</readmoresub fetch_xml_data { my ($ids) = @_; my $dir = 'quicklook/'; my $url = 'http://api.eve-central.com/api/quicklook?typeid='; my $thread_count = 20; my $Q = new Thread::Queue; my @threads; for my $id (@{ $ids }) { $Q->enqueue( $id ); } for ( 1 .. $thread_count ) { push @threads, threads->create( sub { require LWP::Simple; while( my $id = $Q->dequeue ) { say "Downloading XML file for id $id.<br>"; LWP::Simple::getstore( $url.$id, $dir.$id ); } } ); $Q->enqueue( undef ); } $_->join for @threads; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parallel downloading under Win32?
by Corion (Patriarch) on Apr 29, 2009 at 11:58 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 12:11 UTC | |
by ikegami (Patriarch) on Apr 29, 2009 at 12:16 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 12:33 UTC | |
by ikegami (Patriarch) on Apr 29, 2009 at 12:56 UTC | |
| |
by syphilis (Archbishop) on Apr 29, 2009 at 12:27 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 12:31 UTC | |
by syphilis (Archbishop) on Apr 29, 2009 at 13:10 UTC | |
| |
|
Re: Parallel downloading under Win32?
by BrowserUk (Patriarch) on Apr 29, 2009 at 19:36 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 20:05 UTC | |
by Corion (Patriarch) on Apr 29, 2009 at 20:10 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 21:25 UTC | |
by BrowserUk (Patriarch) on Apr 29, 2009 at 21:07 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 21:36 UTC | |
by BrowserUk (Patriarch) on Apr 30, 2009 at 02:17 UTC | |
| |
|
Re: Parallel downloading under Win32?
by spx2 (Deacon) on Apr 29, 2009 at 13:51 UTC |