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)
[解决办法]
试过了能执行
#!/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)
[解决办法]
贴输出。
[解决办法]
应该把全部的源码和输出贴出来