strptime issue in multi-threaded application

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top