坑爹的python thread模块

尼码,今天在琢磨这个模块的使用。

不知道为啥不稳定,在某个站点上看得视频教程,误人子弟啊。完全坑爹。

贴下代码,这是不好的事例。回头找下最优的线程方案。

#!/usr/bin/python
#coding:utf8
import time
import thread

def t1(name,x,l):
    for i in xrange(x):
        print i,name
    l.release()

lock=thread.allocate_lock()

lock.acquire()

thread.start_new_thread(t1,('aaa',10,lock))
thread.start_new_thread(t1,('bbb',10,lock))

while lock.locked():
    pass

 

posted @ 2014-02-24 16:25  墨迹哥's  阅读(404)  评论(0编辑  收藏  举报