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")
RLock参考
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!