【问题标题】:Can't get simple Python threading to work无法让简单的 Python 线程工作
【发布时间】:2013-01-06 02:26:42
【问题描述】:

我是线程新手(虽然不是 Python 的初学者),但我无法让线程正常工作。我有以下 simpl(est) 程序,但我似乎无法调用函数 do_something()。我必须做一些非常基本的错误。谁能告诉我什么?非常感谢!

import threading

def do_something():
    print 'Function called...'

t = threading.Thread(target=do_something)

当然,我之前无意中删除了 t.start() 指令(该死的 Synaptic 触摸板!!!!!!)

【问题讨论】:

    标签: python multithreading


    【解决方案1】:

    你应该启动线程:

    import threading
    
    def do_something():
        print 'Function called...'
    
    t = threading.Thread(target=do_something)
    t.start() # you forgot this line
    

    【讨论】:

      【解决方案2】:

      你需要开始你的话题:

      t.start()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-09
        • 1970-01-01
        • 1970-01-01
        • 2012-09-07
        • 2015-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多