推荐学习书目
› 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
qazwsxkevin
V2EX  ›  Python

请教 concurrent.futures 多进程之间,如何共享变量?

  •  
  •   qazwsxkevin · Nov 29, 2019 · 3700 views
    This topic created in 2500 days ago, the information mentioned may be changed or developed.
    求个例子学习,
    multiprocessing 模块的线程和进程之间共享变量数据的例子在百度上很多
    使用 concurrent.futures 的话,例子翻了很多页都没见到有合适的,请教大家能给个例子的传送门学习?
    感谢感谢~~
    3 replies  •  2019-11-29 23:27:23 +08:00
    wuwukai007
        1
    wuwukai007  
       Nov 29, 2019 via Android
    线程全局变量本身就是共享的,至于函数内变量,可变类型直接传进去就好
    qazwsxkevin
        2
    qazwsxkevin  
    OP
       Nov 29, 2019
    @wuwukai007 明白。。。。


    不是传进变量进进程执行函数。。。
    各个进程都是是同一款执行函数,想让这个函数在执行过程当中传个变量出来(或者说是去对一个全局,其它进程也可以访问的变量进行动态修改),各个进程函数也会在不同的阶段,去读取这个变量去做判断?
    Harlaus
        3
    Harlaus  
       Nov 29, 2019
    task_que = Manager().Queue() # 任务塞队列

    def work(task_que):
    #多进程 worker
    while True:
    size = task_que.qsize()
    if size == 0:
    break
    task = task_que.get()
    就酱
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2452 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:43 · PVG 21:43 · LAX 06:43 · JFK 09:43
    ♥ Do have faith in what you're doing.