读书人

python多线程有关问题

发布时间: 2012-03-17 19:06:27 作者: rapoo

python多线程问题
如下代码,执行后线程0可以执行,但是线程1不能被执行,什么问题?
其中两个线程都是向数据库中加载数据,执行时间都比较长,一般几十秒;

if __name__ == "__main__":

time.sleep(0.2)
thread.start_new_thread(l_thread0,())

time.sleep(0.2)
thread.start_new_thread(l_thread1,())

while True:
time.sleep(1)

[解决办法]
试过了能执行

Python code
#!/usr/bin/env pythonimport thread,timedef l_thread0():    while 1:        print 'this is function ft1.',time.ctime()        time.sleep(1)def l_thread1():    while 1:        print 'this is function ft2.',time.ctime()        time.sleep(1)if __name__ == "__main__":    time.sleep(0.2)    thread.start_new_thread(l_thread0,())    time.sleep(0.2)    thread.start_new_thread(l_thread1,())    while True:        print 'this is main:',time.ctime()        time.sleep(1)
[解决办法]
贴输出。
[解决办法]
应该把全部的源码和输出贴出来

读书人网 >perl python

热点推荐