This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Bbb
Recipients Bbb
Date 2012-10-24.07:14:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1351062852.0.0.92760767978.issue16307@psf.upfronthosting.co.za>
In-reply-to
Content
When using map_async() my callbacks don't get called back.  When using apply_async() they do get called.

CODE:
from multiprocessing import Pool,TimeoutError
from time import sleep

servers=["s1","s2","s3","s4","s5","s6"]
blah = "no callback"

def f(x):
    print("start f(" + x + ")")
    sleep(5)
    print("end   f(" + x + ")")
    return "did " + x

def mycallback(x):
    global blah
    blah = "called back"
    print("My callback " + str(x))
    


def myerrorcallback(r):
    print("My errorcallback " + str(r))


if __name__ == '__main__':
    pool = Pool(processes=7)
    results = pool.map_async(f, servers,  callback=mycallback, error_callback=myerrorcallback)
    print(results.get(timeout=11))
    pool.close()
    pool.join()
    print(blah)

OUTPUT:
D:\python>f.py
start f(s1)
start f(s2)
start f(s3)
start f(s4)
start f(s6)
start f(s5)
end   f(s1)
end   f(s2)
end   f(s3)
end   f(s4)
end   f(s5)
end   f(s6)
['did s1', 'did s2', 'did s3', 'did s4', 'did s5', 'did s6']
no callback

...whereas replacing the code with this:
   with Pool(processes=7) as pool:         # start 4 worker processes
        for server in servers:
            r = pool.apply_async(f, (server,),  callback=mycallback, error_callback=myerrorcallback)
        pool.close()
        pool.join()
        print (blah)


GIVES:
D:\python\f2.py
start f(s1)
start f(s2)
start f(s3)
start f(s4)
start f(s5)
start f(s6)
end   f(s2)
end   f(s1)
My callback did s2
My callback did s1
end   f(s4)
My callback did s4
end   f(s3)
My callback did s3
end   f(s5)
My callback did s5
end   f(s6)
My callback did s6
called back


This is v3.3 on Windows XP.
History
Date User Action Args
2012-10-24 07:14:12Bbbsetrecipients: + Bbb
2012-10-24 07:14:12Bbbsetmessageid: <1351062852.0.0.92760767978.issue16307@psf.upfronthosting.co.za>
2012-10-24 07:14:11Bbblinkissue16307 messages
2012-10-24 07:14:11Bbbcreate