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

python 中关于多线程的有关问题

2012-03-04 
python 中关于多线程的问题# codinggbkimport timeimport threaddef timer(no,interval): #自己写的线程

python 中关于多线程的问题
# coding=gbk
import time
import thread  

def timer(no,interval): #自己写的线程函数
  while True:
  print 'Thread :(%d) Time:%s'%(no,time.ctime())
  time.sleep(0)
   
   
def test():#使用thread.start_new_thread()来产生2个新的线程
  thread.start_new_thread(timer,(2,3))
  thread.start_new_thread(timer,(1,1))
   
   
if __name__=='__main__':
  test()


为什么我的输出了一行信息就结束了?
输出的信息是:Thread :(2) Time:Mon Feb 18 14:02:32 2008



[解决办法]
你的主线程退出了,程序就推出了,从线程还没执行呢。

Python code
def test():    thread.start_new_thread(timer,(2,3))    thread.start_new_thread(timer,(1,1))    time.sleep(1)#加上试试 

热点排行