V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
aheadlead
V2EX  ›  Python

自己挖了一个坑,分享一下关于 threading 的小教训

  •  
  •   aheadlead · Mar 5, 2015 · 3622 views
    This topic created in 4072 days ago, the information mentioned may be changed or developed.
    我把 Thread 里面的 start 方法和 run 方法记混了…

    start 是启动线程
    run 是执行线程的 target


    然后我遇到了“主线程莫名其妙阻塞”的问题…233

    还是老老实实查文档好…大家尽情的嘲讽我吧
    7 replies    2015-03-05 20:32:05 +08:00
    fanta
        1
    fanta  
       Mar 5, 2015
    [code]
    import os
    import thread
    import threading


    def run(*args, **kwargs):
    t = threading.current_thread()
    print "ppid:", os.getppid(), "pid:", os.getpid(), "tid:", thread.get_ident(), "ident:", t.ident, "tname:", t.getName()


    def main():
    run()
    t = threading.Thread(target=run).start()


    if __name__ == "__main__":
    main()
    [/code]
    fanta
        2
    fanta  
       Mar 5, 2015
    一个thread测试.
    cougar
        3
    cougar  
       Mar 5, 2015
    我是看楼主头像才进来的
    inevermore
        4
    inevermore  
       Mar 5, 2015
    这不算坑,你对线程不熟悉吧。
    Java还有C++自己封装的,都是这样
    aheadlead
        5
    aheadlead  
    OP
       Mar 5, 2015 via iPhone
    @inevermore 好久没写程序了... 好多都不记得去了
    dreamtrail
        6
    dreamtrail  
       Mar 5, 2015
    有multiprocessing就够了, 从不用thread
    ZRS
        7
    ZRS  
       Mar 5, 2015
    233333333333
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5846 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 63ms · UTC 03:08 · PVG 11:08 · LAX 20:08 · JFK 23:08
    ♥ Do have faith in what you're doing.