jeudi 5 novembre 2015

Print from starmap_async() pool worker

Vote count: 0

I'd like to throw out some basic status text from my pool workers, but I'm not getting any joy on the shell. I do get the return value of the function, when a worker has finished. But the print(q) outputs nothing.

The effect is identical if i replace starmap_async() with regular map_async() and unpack the q, p input inside le_funk().

This is a basic mock-up of what I'm trying to do:

import multiprocessing as mp

def le_funk(q,p):
    print(q)
    return(q+p)


if __name__ == '__main__':
    with mp.Pool(maxtasksperchild=1) as pool: 
        arg = [('a','b'), ('e','f'), ('i','j'), ('o','p'), ('u','v')]
        res = pool.starmap_async(le_funk, arg)
        # Stay calm and wait for workers to finish.
        res.wait()
        print(res.get())

I've seen it done here so apparently its possible. They just use the older non-with setup but either gives no print output in my python 3.5 windows terminal.

asked 3 mins ago

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.



Print from starmap_async() pool worker

Aucun commentaire:

Enregistrer un commentaire