首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python多线程有关问题

2012-03-17 
python多线程问题如下代码,执行后线程0可以执行,但是线程1不能被执行,什么问题?其中两个线程都是向数据库

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)
[解决办法]
贴输出。
[解决办法]
应该把全部的源码和输出贴出来

热点排行