- 论坛徽章:
- 0
|
用Python 2.7版本写了一个简单有关线程的程序,代码如下:- import threading
- from time import ctime,sleep
- def music(func):
- for i in range(2):
- print 'I was listening to %s.%s'%(func,ctime())
- sleep(1)
- def movie(func):
- for i in range(2):
- print 'I was at the %s.%s'%(func,ctime())
- sleep(5)
- threads=[]
- t1=threading.Thread(target=music,args=(u'爱情买卖',))
- threads.append(t1)
- t2=threading.Thread(target=movie,args=(u'阿凡达',))
- threads.append(t2)
- if __name__=='__main__':
- for t in threads:
- t.setDaemon(True)
- t.start()
- t.join()
- print 'all over %s'%ctime()
复制代码 但是执行的时候出错了,提示:Runtime Error!
希望大大们能帮忙看看原因在哪?找不到哪里出错了。先谢谢大家! |
|