V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2015-03-05 12:02:39 +08:00 · 2926 次点击
    这是一个创建于 3347 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我把 Thread 里面的 start 方法和 run 方法记混了…

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


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

    还是老老实实查文档好…大家尽情的嘲讽我吧
    7 条回复    2015-03-05 20:32:05 +08:00
    fanta
        1
    fanta  
       2015-03-05 12:05:34 +08:00
    [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  
       2015-03-05 12:06:20 +08:00
    一个thread测试.
    cougar
        3
    cougar  
       2015-03-05 12:35:57 +08:00
    我是看楼主头像才进来的
    inevermore
        4
    inevermore  
       2015-03-05 12:45:41 +08:00
    这不算坑,你对线程不熟悉吧。
    Java还有C++自己封装的,都是这样
    aheadlead
        5
    aheadlead  
    OP
       2015-03-05 13:05:04 +08:00 via iPhone
    @inevermore 好久没写程序了... 好多都不记得去了
    dreamtrail
        6
    dreamtrail  
       2015-03-05 14:14:34 +08:00
    有multiprocessing就够了, 从不用thread
    ZRS
        7
    ZRS  
       2015-03-05 20:32:05 +08:00
    233333333333
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2269 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:21 · PVG 23:21 · LAX 08:21 · JFK 11:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.