python使用multiprocessing模块实现带回调函数的异步调用方法
本文实例讲述了python使用multiprocessing模块实现带回调函数的异步调用方法。分享给大家供大家参考。具体分析如下:
multipressing模块是python2.6版本加入的,通过这个模块可以轻松实现异步调用
frommultiprocessingimportPool deff(x): returnx*x if__name__=='__main__': pool=Pool(processes=1) #Startaworkerprocesses. result=pool.apply_async(f,[10],callback) #Evaluate"f(10)"asynchronouslycallingcallbackwhenfinished.
希望本文所述对大家的Python程序设计有所帮助。