-
-
Save chekunkov/5520742 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""I suspect that there is a race condition in datetime module. | |
When I ran the following code in a multi-threading application: | |
datetime.datetime.strptime('20120509100335', "%Y%m%d%H%M%S") | |
I've noticed the following error in the log. | |
Traceback (most recent call last): | |
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner | |
self.run() | |
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 477, in run | |
self.__target(*self.__args, **self.__kwargs) | |
File "a.py", line 18, in f | |
datetime.datetime.strptime('20120509100335', "%Y%m%d%H%M%S") | |
AttributeError: _strptime | |
This behavior is not predictable. This program tries to reproduce that behavior. | |
""" | |
import sys | |
import threading | |
import datetime | |
def f(): | |
print "BEGIN", threading.currentThread().getName() | |
for i in range(100): | |
datetime.datetime.strptime('20120509100335', "%Y%m%d%H%M%S") | |
print "END", threading.currentThread().getName() | |
def main(): | |
threads = [threading.Thread(target=f) for i in range(10)] | |
for t in threads: | |
t.start() | |
for t in threads: | |
t.join() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment