Problems with gencache on Windows NT
Geoff Talvola
gtalvola at nameconnector.com
Thu May 10 13:29:44 EDT 2001
At 12:26 PM 5/10/01 -0400, Geoff Talvola wrote:
>Actually, I just today discovered a gotcha with using EnsureDispatch. It
>appears to be non-thread-safe. If multiple threads are simultaneously
>trying to EnsureDispatch, I get problems.
>
>My solution for now is to just use EnsureModule at import time, but that
>obviously defeats the purpose of EnsureDispatch.
>
>So it would be nice if EnsureDispatch could be made thread-safe. Another
>solution would be to allow EnsureModule to be passed in a nice string like
>"Scripting.Dictionary" instead of the GUID, to make it nicer to use.
I experimented a bit with this, and it turns out that an easy way to make
both EnsureDispatch and EnsureModule thread-safe is to simply wrap the
entire contents of EnsureModule with a lock. Mark, any chance this fix
could be made in gencache.py? I made this change in my copy of gencache.py
and it fixed my problem:
import threading
_ensureModuleLock = threading.Lock()
def EnsureModule(...):
_ensureModuleLock.acquire()
try:
# do the EnsureModule thing here...
finally:
_ensureModuleLock.release()
--
- Geoff Talvola
gtalvola at NameConnector.com
More information about the Python-list
mailing list