J
Joe Holloway
We recently uplifted our web application to run on Python 2.6.2.
We've noticed on a couple occasions that calls into time.strptime have
failed with this exception:
ImportError: Failed to import _strptime because the import lockis
[sic] held by another thread.
I poked around the source code enough to realize that this is
apparently due to time.strptime using PyImport_ImportModuleNoBlock
which potentially raises an ImportError rather than waiting for the
"import lock" to be released [1]. This appears to have been
introduced as a workaround for other thread safety concerns [2].
Does this indicate that strptime and any other library function that
uses the non-blocking import call in this fashion are not thread safe?
Is there an idiomatic way of dealing with this error in
multi-threaded applications?
Like I mentioned, it's only happened on a couple occasions because the
right conditions have to be in place, but something doesn't seem right
about it. I thought I'd ask on the mailing list before going so far
as to open a ticket, but feel free to direct me there if that's the
appropriate place for this.
Thanks,
Joe
[1] http://www.python.org/doc/2.6/c-api/import.html#PyImport_ImportModuleNoBlock
[2] http://svn.python.org/view?view=rev&revision=59678
We've noticed on a couple occasions that calls into time.strptime have
failed with this exception:
ImportError: Failed to import _strptime because the import lockis
[sic] held by another thread.
I poked around the source code enough to realize that this is
apparently due to time.strptime using PyImport_ImportModuleNoBlock
which potentially raises an ImportError rather than waiting for the
"import lock" to be released [1]. This appears to have been
introduced as a workaround for other thread safety concerns [2].
Does this indicate that strptime and any other library function that
uses the non-blocking import call in this fashion are not thread safe?
Is there an idiomatic way of dealing with this error in
multi-threaded applications?
Like I mentioned, it's only happened on a couple occasions because the
right conditions have to be in place, but something doesn't seem right
about it. I thought I'd ask on the mailing list before going so far
as to open a ticket, but feel free to direct me there if that's the
appropriate place for this.
Thanks,
Joe
[1] http://www.python.org/doc/2.6/c-api/import.html#PyImport_ImportModuleNoBlock
[2] http://svn.python.org/view?view=rev&revision=59678