Using python multiprocessing Pool in the terminal and in code modules for Django or Flask
问题 When using multiprocessing.Pool in python with the following code, there is some bizarre behavior. from multiprocessing import Pool p = Pool(3) def f(x): return x threads = [p.apply_async(f, [i]) for i in range(20)] for t in threads: try: print(t.get(timeout=1)) except Exception: pass I get the following error three times (one for each thread in the pool), and it prints "3" through "19": AttributeError: 'module' object has no attribute 'f' The first three apply_async calls never return.