Bug in (datetime|time).strptime - AttributeError: _strptime

 Issue 7980


This bug occurs only when you use threads and only once.

import datetime
import thread
[thread.start_new_thread(lambda : datetime.datetime.strptime("20161015","%Y%m%d"), ()) for _ in range(2)]
view raw strptime.py hosted with ❤ by GitHub
Of course, this method is thread safe, but there is a severe warning. The first use of strptime is not thread secure (underneath _strptime is imported, and the import may throw AttributeError). If you want to avoid this problem, either you have to call strptime or import _strptime before starting a thread.

How to fix it?

Just import _strptime or call strptime before starting a thread.

import datetime
import thread
import _strptime
[thread.start_new_thread(lambda : datetime.datetime.strptime("20161015","%Y%m%d"), ()) for _ in range(2)]
view raw strptime.py hosted with ❤ by GitHub
It seems that it happens since 2010.

Comments

Popular posts from this blog

GitLab - extends keyword

Managing Secrets in GitLab / Git

GitLab - trigger keyword