how to write thread-safe module ? and pytz

nicolas_riesch nicolas.riesch at
Wed Aug 10 15:06:09 CEST 2005

Does someone know if the module pytz
( is thread-safe ?
I have not seen it explicitely stated, and just wanted to be sure, as I
want to use it.

That's because in the file pytz/, I see global variables
_timedelta_cache, _datetime_cache, _ttinfo_cache, which are
dictionnaries and are used as cache.
I always thought that you must protect shared data with locks when
multithreading, but I don't see any lock anywhere in pytz.
However, pytz seems to work well with multiple threads creating various
timezone objects at the same time.
I don't understand where the trick is, that allows multiple threads to
access this module without any locking and that all this seems to work
without any problem...

Does this mean that there is a means to write a module that is
thread-safe, without importing the threading module and creating locks

Or have I not understood something ...?

Can someone give me a hint ?

More information about the Python-list mailing list