[Python-bugs-list] [Bug #130306] statcache.py full of thread problems

noreply@sourceforge.net noreply@sourceforge.net
Sat, 27 Jan 2001 18:13:24 -0800


Bug #130306, was updated on 2001-Jan-27 18:13
Here is a current snapshot of the bug.

Project: Python
Category: Threads
Status: Open
Resolution: None
Bug Group: None
Priority: 6
Submitted by: tim_one
Assigned to : tim_one
Summary: statcache.py full of thread problems

Details: From c.l.py (I'll skip including my reply):

From: Randall Kern mailto:randy@spoke.net
Sent: Saturday, January 27, 2001 7:20 PM
Subject: threading issues with statcache

Looking at the code for the statcache module from py 1.5.2, it looks like
it isn't thread safe.  While writing my own substitute, I realized I am
unclear on when names are looked up.

In particular, given two function like these (copied from statcache):

cache = {}
def stat(path):
    if cache.has_key(path):
        return cache[path]

    cache[path] = ret = os.stat(path)
    return ret

def reset():
    global cache
    cache = {}


If the symbol 'cache' is looked up _once_ per function, then these two
functions may be used across multiple threads.  If it is looked up for
every reference, than it would be possible to call reset() between a TRUE
has_key() and the return in stat(), which would result in a KeyError.

When are global variable's bound?

Thanks,
-Randy

P.S. I realize that stat() might update the cache more than once for the
same path, if it was called from multiple threads. But that's consistent
with it's expected behavior, so not really a MT problem.


For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=130306&group_id=5470