在使用threading模块时出现的一个小问题
2013-02-04 12:01
387 查看
#!/usr/bin/env python import threading from time import sleep, ctime loops = [4, 2] def loop(nloop, nsec): print 'start loop', nloop, 'at:', ctime() sleep(nsec) print 'loop', nloop, 'done at:', ctime() def main(): print 'starting at:', ctime() thread = [] nloops = range(len(loops)) for i in nloops: t = threading.Thread(target=loop, args=(i, loops[i])) thread.append(t) for i in nloops: thread[i].start() for i in nloops: thread[i].join() print 'all DONE at:', ctime() if __name__ == '__main__': main()
在学习threading时写了一个如上代码,然后保存threading.py后执行出现如下错误
[root@linux-vm scripts]#
./threading.py
starting at: Fri Aug 31 18:49:50 2012
Traceback (most
recent call last):
File "./multithread.py", line 31, in <module>
main()
File "./multithread.py", line 19, in main
t =
threading.Thread(target=loop, args=(i, loops))
AttributeError: 'module'
object has no attribute 'Thread'
Exception AttributeError: '_shutdown' in
<module 'threading' from '/data/scripts/threading.pyc'>
ignored
仔细看报错信息发现是threading.pyc有问题,后来经过研究发现是因为在程序中使用了import
threading语句导入threading模块,而文件名本身又叫threading.py所以直接导入的是程序本身,将程序名改名后,再将threading.pyc删除后正常。另外需要注意如果仅仅是程序名改名后而不删除threading.pyc的话,还是会报同样的错误。
相关文章推荐
- 在虚拟机的XP中使用管道出现的问题,可能是一个BUG,先记录下来
- 关于解决在使用opencv时出现*.exe 已触发了一个断点的问题
- 使用Foreach时出现的一个小问题
- FF上使用jquery ajax时出现一个小问题
- POSIX timer函数 timer_creat()使用中出现的一个问题
- 深入springMVC------文件上传源码解析(上篇) 最近在项目中,使用springmvc 进行上传文件时,出现了一个问题: org.springframework.web.multipart
- 使用require出现循环依赖模块报错的问题
- 一个链表在使用时出现内存错误的问题
- 解决OpenCV在使用摄像头捕捉视频流时出现的一个奇怪问题
- 在使用Oracle9Ii时出现的一个问题~~
- 5.0及以上系统上使用CircleImageView圆形头像出现方块背景问题(上一个Activity中的页面)
- linux使用velocity出现的一个奇葩问题-Unable to find resource
- 在Linux中使用vi/vim打开一个文件时出现的的问题
- 使用网络目录映射虚拟目录出现 500.19 权限不足问题的一个解决办法
- 今天使用VS2015遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"
- [Latex] tikz包使用时出现的一个问题及解决
- 使用SQL Developer导入文件时出现的一个奇怪的问题
- 一个Eigen库使用时的出现的问题(complex的头文件兼容性)
- 最近使用ajaxFileUpload和Jcrop来实现图片上传和截图,出现一个图片无法更换的问题
- 关于使用JSONObject出现的一个小问题