<s> from concurrent import futures <EOL> import sys <EOL> import requests <EOL> import countryflags as cf <EOL> import time <EOL> from getsequential import fetch <EOL> DEFAULT_NUM_THREADS = <NUM_LIT:100> <EOL> GLOBAL_TIMEOUT = <NUM_LIT> <EOL> times = { } <EOL> def main ( source , num_threads ) : <EOL> pool = futures . ThreadPoolExecutor ( num_threads ) <EOL> pending = { } <EOL> t0 = time . time ( ) <EOL> for iso_cc in sorted ( cf . cc2name ) : <EOL> print ( '<STR_LIT>' , iso_cc ) <EOL> times [ iso_cc ] = [ time . time ( ) - t0 ] <EOL> job = pool . submit ( fetch , iso_cc , source ) <EOL> pending [ job ] = iso_cc <EOL> to_download = len ( pending ) <EOL> downloaded = <NUM_LIT:0> <EOL> for job in futures . as_completed ( pending , timeout = GLOBAL_TIMEOUT ) : <EOL> try : <EOL> octets , file_name = job . result ( ) <EOL> times [ pending [ job ] ] . append ( time . time ( ) - t0 ) <EOL> downloaded += <NUM_LIT:1> <EOL> print ( '<STR_LIT>' . format ( file_name , octets ) ) <EOL> except Exception as exc : <EOL> print ( '<STR_LIT>' , pending [ job ] , '<STR_LIT>' , exc ) <EOL> ratio = downloaded / to_download <EOL> print ( '<STR_LIT>' . format ( downloaded , to_download , ratio ) ) <EOL> for iso_cc in sorted ( times ) : <EOL> start , end = times [ iso_cc ] <EOL> print ( '<STR_LIT>' . format ( iso_cc , start , end ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import argparse <EOL> source_names = '<STR_LIT:U+002CU+0020>' . join ( sorted ( cf . SOURCE_URLS ) ) <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:source>' , help = '<STR_LIT>' + source_names ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = int , default = DEFAULT_NUM_THREADS , <EOL> help = '<STR_LIT>' % DEFAULT_NUM_THREADS ) <EOL> args = parser . parse_args ( ) <EOL> main ( args . source , args . threads ) <EOL> """<STR_LIT>""" </s>
