New submission from Bbb: 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. ---------- components: Library (Lib) messages: 173653 nosy: Bbb priority: normal severity: normal status: open title: multiprocess.pool.map_async callables not working type: behavior versions: Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16307> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com