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

请教下关于多线程协调的

  •  
  •   lbxx · Oct 3, 2016 · 3244 views
    This topic created in 3530 days ago, the information mentioned may be changed or developed.
    现在有 1 万件事(按 1-10000 排列),给 4 个线程 ABCD 去做,每件事处理完的数据都要存进 MYSQL
    那么这 4 个线程之间改如何协调?

    比如 A 干了 1 ,那么 B 就不应该再去做 1 ,而是做 2

    我能想到的就是给个 list 将做过的事情标记起来,比如 [1,2],但是总感觉这样不行,有无其他好方法?
    10 replies    2016-10-05 11:36:25 +08:00
    bianzhifu
        1
    bianzhifu  
       Oct 3, 2016 via Android
    Queue
    zhuangzhuang1988
        2
    zhuangzhuang1988  
       Oct 3, 2016 via iPad
    推荐看这个, https://book.douban.com/subject/4214617/ Windows 并发编程指南,
    里面有详细记载关于任务分割的几种方法,优缺点,还有些高级技术
    aploium
        3
    aploium  
       Oct 4, 2016
    https://github.com/aploium/mpms

    用 Queue, 这是个 demo (好吧其实是写给自己用的简陋框架),
    使用 5 个进程, 每个进程 10 个线程, 下载 1000 次 http://example.com 并保存到文件
    aploium
        4
    aploium  
       Oct 4, 2016
    准确地说是下载 http://example.com/?q=1http://example.com/?q=1000 一共 1000 条 url
    aihimmel
        5
    aihimmel  
       Oct 4, 2016 via Android
    简单的话可以用一个全局变量解决?
    线程内用循环。。
    lbxx
        6
    lbxx  
    OP
       Oct 4, 2016
    @bianzhifu
    @aploium Nice 感谢。学习下
    lbxx
        7
    lbxx  
    OP
       Oct 4, 2016
    slysly759
        8
    slysly759  
       Oct 5, 2016 via Android
    pool.map
    hrong
        9
    hrong  
       Oct 5, 2016 via Android
    JAVA 的话 fork join
    fhefh
        10
    fhefh  
       Oct 5, 2016
    nice~~~ mark
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5338 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 07:31 · PVG 15:31 · LAX 00:31 · JFK 03:31
    ♥ Do have faith in what you're doing.