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

多线程为什么有一个线程出错其他的就卡死??

  •  
  •   wuxiaolin · Apr 24, 2013 · 7529 views
    This topic created in 4777 days ago, the information mentioned may be changed or developed.
    del test():
    a()
    b()
    c()

    del f():
    threadPool = []
    for a in b:
    t = threading.Thread(target=test,args=())
    threadPool.append(t)
    t.start()

    for t in threadPool:
    t.join()

    #执行其他操作



    这样的形式进行多线程,每个线程分别执行test方法,test方法调用3个方法只要一个方法错误,就直接导致其他的线程也无法运行出现僵尸进程,而且#执行其他操作 那下面的代码也无法执行。这是为什么?不是应该一个线程出错也不会影响其他线程的执行么???
    9 replies    1970-01-01 08:00:00 +08:00
    zlbruce
        1
    zlbruce  
       Apr 24, 2013
    因为整个进程挂了呗
    所以我喜欢多进程
    wuxiaolin
        2
    wuxiaolin  
    OP
       Apr 24, 2013
    @zlbruce 怎么一个线程会影响到整个进程滴,哎,好蛋疼啊,而且进程变成僵尸进程一直卡死在那里
    46fo
        3
    46fo  
       Apr 24, 2013
    有锁 造成死锁了
    wuxiaolin
        4
    wuxiaolin  
    OP
       Apr 24, 2013
    @xdeng 那是否在try 捕捉到错误时释放锁就可以了
    46fo
        5
    46fo  
       Apr 24, 2013   ❤️ 1
    必须的啊~ 有锁不释放 肯定别的阻塞啊

    记得给分 最近 穷
    maxint64
        6
    maxint64  
       Apr 24, 2013   ❤️ 1
    @wuxiaolin 线程和进程不同,多个进程的内存空间是相互独立的,所以某个进程崩掉不影响其他进程。但同一进程下的多个线程是共享内存空间的,一个线程崩掉,其它的也活不了。
    VYSE
        7
    VYSE  
       Apr 25, 2013   ❤️ 1
    Python的多线程其实就是一根筋,异常抛给Threading,它也不会给你处理还是往外抛,然后其他线程也就不可能解锁了
    Zuckonit
        8
    Zuckonit  
       Apr 25, 2013
    同一进程的各个线程的资源是共享的, 有锁。。。
    banbanchs
        9
    banbanchs  
       Apr 25, 2013
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2913 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 07:03 · PVG 15:03 · LAX 00:03 · JFK 03:03
    ♥ Do have faith in what you're doing.