python 代码问题求教 - V2EX
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
nettest

python 代码问题求教

  •  
  •   nettest Apr 17, 2015 3745 views
    This topic created in 4067 days ago, the information mentioned may be changed or developed.

    代码v2ex不显示格式,我传了个图。: http://ww3.sinaimg.cn/mw1024/005R8CzCjw1er8sbmqqpfj30cl09yq3r.jpg

    from multiprocessing import Pool

    def openit(i,data1):
    print i
    data1.append(i)
    if name=='main':
    data=['a','b','c','d','e','f']
    data1=[]
    print 'Start!'
    p = Pool(6)
    for i in data:
    p.apply_async(openit, args=(i,data1))
    p.close()
    p.join()
    print 'Done',data1

    这个代码为什么输出的data1空的
    执行结果:Start!
    a
    b
    c
    e
    d
    f
    Done []

    4 replies    2015-04-20 13:35:26 +08:00
    xanpeng
        1
    xanpeng  
       Apr 18, 2015   1
    python进程间变量共享问题,参考这篇文章“浅谈 python multiprocessing(多进程)下如何共享变量”(http://my.oschina.net/leejun2005/blog/203148),以及其中相关链接。
    nettest
        2
    nettest  
    OP
       Apr 18, 2015
    @xanpeng 好哒\(^o^)/,的确是变量问题。
    nettest
        3
    nettest  
    OP
       Apr 18, 2015
    @xanpeng Manager是否只能在linux下运行?测试了给的链接里的第一个代码,结果win报错,linux正常。
    xanpeng
        4
    xanpeng  
       Apr 20, 2015   1
    @nettest 这个我实际也少用到,应该不是只适用linux吧,毕竟python是跨平台的,且文档(https://docs.python.org/2/library/multiprocessing.html#managers)也没有提到不适用win。
    win报错得你自查了,我没有win环境。不过manager貌似非唯一方法,可试试其他的。
    About     Help     Advertise     Blog     API     FAQ     Solana     2808 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 34ms UTC 13:20 PVG 21:20 LAX 06:20 JFK 09:20
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86