'module' Object Has No Attribute '_strptime' With Several Threads Python
Solution 1:
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
Solution 2:
The problem is described in a mailing list message "threading bug in strptime".
datetime.strptime
has a problem with Python 2's threading
module. The workaround suggested there seems to be to invoke strptime = datetime.datetime.strptime
before any threads are started.
Solution 3:
Just ran into this exact problem. It's a tricky one - took me an hour or so to track it down. I tried launching the shell and entering in the following code:
import datetime
print(datetime.datetime.strptime("2015-4-4", "%Y-%m-%d"))
This worked fine. Then I tried it in a blank file in my workspace. This gave the same error you described. I tried running it from the command line in my workspace. Still gave the error. I then launched the shell from my workspace. This time it gave the error in the shell environment. As it turned out, any directory other than the one I was in worked fine.
The problem was that my project was a python calendar app, and my main file was called "calendar.py". This conflicted with some native import, thus creating the bizarre error.
In your case, I'd bet anything the problem is the name of your file: "file.py". Call it something else, and you should be good to go.
Solution 4:
I was running into this issue when testing out a script that had been working on Linux on a Windows machine, and I was able to fix it by simply adding an import statement at the top of the thread.
defmultithreadedFunction():
from datetime import datetime
# Rest of the function
Probably worth trying this out before modifying your function to not use the datetime module, since this is a much quicker fix if it works.
Solution 5:
Same error in my thread module which uses the datetime.strptime() method.
As filed in https://bugs.python.org/issue7980, that method does not import _strptime.py in a thread safe way.
One of the last comments says that: "this is a Python 2.7-only bug, and it's not a security issue, so the issue may be closed as either "wontfix" (because we won't fix it in Python 2) or "fixed" (because it is already fixed in Python 3), depending on your perspective."
Post a Comment for "'module' Object Has No Attribute '_strptime' With Several Threads Python"