def run_mp(songs):
    """
    Concurrently calls get_lyrics to fetch the lyrics of a large list of songs.
    """
    stats = Stats()
    if CONFIG['debug']:
        good = open('found', 'w')
        bad = open('notfound', 'w')

    logger.debug('Launching a pool of %d processes\n', CONFIG['jobcount'])
    chunksize = math.ceil(len(songs) / os.cpu_count())
    try:
        with Pool(CONFIG['jobcount']) as pool:
            for result in pool.imap_unordered(get_lyrics, songs, chunksize):
                if result is None:
                    continue

                for source, runtime in result.runtimes.items():
                    stats.add_result(source, result.source == source, runtime)

                found = process_result(result)
                if CONFIG['debug']:
                    if found:
                        good.write(f'{id_source(source)}: {result.song}\n')
                        good.flush()
                    else:
                        bad.write(str(result.song) + '\n')
                        bad.flush()

    finally:
        if CONFIG['debug']:
            good.close()
            bad.close()

    return stats
def run_mp ( songs ) : stats = Stats ( ) if CONFIG [ 'debug' ] : good = open ( 'found' , 'w' ) bad = open ( 'notfound' , 'w' ) logger . debug ( 'Launching a pool of %d processes\n' , CONFIG [ 'jobcount' ] ) chunksize = math . ceil ( len ( songs ) / os . cpu_count ( ) ) try : with Pool ( CONFIG [ 'jobcount' ] ) as pool : for result in pool . imap_unordered ( get_lyrics , songs , chunksize ) : if result is None : continue for source , runtime in result . runtimes . items ( ) : stats . add_result ( source , result . source == source , runtime ) found = process_result ( result ) if CONFIG [ 'debug' ] : if found : good . write ( f'{id_source(source)}: {result.song}\n' ) good . flush ( ) else : bad . write ( str ( result . song ) + '\n' ) bad . flush ( ) finally : if CONFIG [ 'debug' ] : good . close ( ) bad . close ( ) return stats
Concurrently calls get_lyrics to fetch the lyrics of a large list of songs.