Python多线程下的_strptime问题
2016-04-30 02:39
471 查看
Python多线程下的_strptime问题
由于Python的datetime和time中的_strptime方法不支持多线程,运行时会报错:import datetime
import thread
import time
def f():
datetime.datetime.strptime("20100101","%Y%m%d")
for _ in xrange(3):
thread.start_new_thread(f, ())
time.sleep(3)
Unhandled exception in thread started by <function f at 0x2b52c24e66e0>
Traceback (most recent call last):
File "test.py", line 7, in f
datetime.datetime.strptime("20100101","%Y%m%d")
AttributeErrorUnhandled exception in thread started by <function f at 0x2b52c24e66e0>:
Traceback (most recent call last):
File "test.py", line 7, in f
_strptime
datetime.datetime.strptime("20100101","%Y%m%d")
AttributeError: _strptime
参考 http://bugs.python.org/issue7980
在源文件中可以fix这个bug,不过对于用户来说,还是在使用的时候加锁吧。。
c = threading.RLock()
def f():
with c:
datetime.datetime.strptime("20100101","%Y%m%d")
相关文章推荐
- Python多线程下的_strptime问题
- Python调用C库
- Python调用C库
- Python按位运算符,字典,运算符优先级的基本总结
- Python - 字母算术谜题
- Python str内部功能介绍
- python 多线程 join 的 细节问题 注意使用事项
- Python开发环境配置
- 如何在MAC 指定文件夹打开终端(terminal)
- python 函数超时装饰器
- python 正则表达式
- python web中models.py中的一些处理
- win下python和opencv安装
- python解决网站的反爬虫策略
- python3.5使用pip安装scrapy时unable to find vcvarsall.bat异常处理
- knn算法python实现
- python解决八皇后问题
- Regular Expression Python
- 基于python的爬虫---自顶向下的设计思想
- python学习5