Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'module' object has no attribute '_strptime' with several threads Python

I'm getting this error 'module' object has no attribute '_strptime' but only when I use several threads. When I only use one it works fine. Im using python 2.7 x64. Here there us the reduced function i'm calling

import datetime def get_month(time):     return datetime.datetime.strptime(time, '%Y-%m-%dT%H:%M:%S+0000').strftime("%B").lower() 

Here is the complete traceback:

AttributeError: 'module' object has no attribute '_strptime'  Exception in thread Thread-22: Traceback (most recent call last):   File "C:\Python27x64\lib\threading.py", line 810, in __bootstrap_inner     self.run()   File "C:\Python27x64\lib\threading.py", line 763, in run     self.__target(*self.__args, **self.__kwargs)   File "C:\file.py", line 81, in main     month=get_month(eventtime)   File "C:\file.py", line 62, in get_month     return datetime.datetime.strptime(time, '%Y-%m-%dT%H:%M:%S+0000').strftime("%B").lower() AttributeError: 'module' object has no attribute '_strptime' 
like image 502
user1618465 Avatar asked Aug 27 '15 09:08

user1618465


1 Answers

I can confirm that the issue is related to multithreading, and it happens to me occasionally when I use datetime.datetime.strptime in combination with the ThreadPool module.

I was able to fix this in my script by importing the "missing" module as follows:

import _strptime 
like image 87
chrki Avatar answered Oct 05 '22 23:10

chrki