Robert Collins added the comment:

Oh, it may be clear to everyone already but its perhaps worth noting: there are 
two ways the cache can skew.

(older source): We may have a newer file compiled and in use and the older 
source in the cache.

e.g. someone calls linecache.getlines(foo.py), then imports foo, and in between 
the contents of foo.py changed.

(newer source) Or we may have an older file compiled and in use, and newer 
source in the cache.

e.g. someone imports foo, the contents of foo.py change, and then someone calls 
linecache.getlines(foo.py).

One way to address the older source case would be to make importing (also 
compile()) flush the imported file out of the cache. That doesn't need any 
special logic or handling - just a new parameter to clearcache() to specify  a 
file (or files?) to evict.

The newer source case is what needs some logic, and for that, as I said 
earlier, I think we need something opaque. Perhaps since we have importlib now, 
if we limit ourselves to considering actual python modules (linecache can 
technically cache anything with lines in it) we can rely on the import 
machinery get_source() to handle this: if the source has changed get_source 
should return None.

That way we don't need to change the data structure of modules at all - only 
packages for which there is no 302 loader will be able to suffer cache skew.

As far as informing callers that this situation has occurred, I think we'll 
need to think a bit about that, as linecache already signals 'source not 
available' by returning None, which doesn't leave much room to include an error 
message. We could start raising exceptions up the stack - which implies 
modifying PEP-302 (e.g. via a new PEP) and working up the stack.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8087>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to