推荐学习书目
› 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 · 4084 views
    This topic created in 4261 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
    fanta
    Mar 5, 2015
    1
    [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
    fanta
    Mar 5, 2015
    2
    一个thread测试.
    cougar
    cougar
    Mar 5, 2015
    3
    我是看楼主头像才进来的
    inevermore
    inevermore
    Mar 5, 2015
    4
    这不算坑,你对线程不熟悉吧。
    Java还有C++自己封装的,都是这样
    aheadlead
    aheadlead
    OP
    Mar 5, 2015 via iPhone
    5
    @inevermore 好久没写程序了... 好多都不记得去了
    dreamtrail
    dreamtrail
    Mar 5, 2015
    6
    有multiprocessing就够了, 从不用thread
    ZRS
    ZRS
    Mar 5, 2015
    7
    233333333333
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5044 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 01:43 · PVG 09:43 · LAX 17:43 · JFK 20:43
    ♥ Do have faith in what you're doing.