python - 当装饰器遇到multiprocessing, 出了点bug.
天蓬老师
天蓬老师 2017-04-18 10:30:27
0
3
675
from multiprocessing import Pool def with_app_context(need_new=False): def magic(func): app_store = {} def wrapper(*args, **kwargs): print 'inside', args, kwargs result = func(*args, **kwargs) return result return wrapper return magic @with_app_context(need_new=True) def func(k1, k2): print k1, k2 return 'ret' pool = Pool(processes=1) pool.apply_async(func, args=('hi', 'yo')) pool.close() pool.join()

什么结果都不输出, 请问哪有bug?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复 (3)
Peter_Zhu

似乎是这个原因,函数装饰器不可pickle
可以看看这个:
装饰器与多进程以及Pickle

  • 扩展: Python MultiProcessing 使用心得

    阿神

    我已经找到原因了:

    Traceback (most recent call last): File "wrapper.py", line 30, in  print ret.get() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 567, in get raise self._value cPickle.PicklingError: Can't pickle : attribute lookup __builtin__.function failed

    子进程异常.

      洪涛

      http://stackoverflow.com/ques...

        最新下载
        更多>
        网站特效
        网站源码
        网站素材
        前端模板
        关于我们 免责声明 Sitemap
        PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!