Author rbcollins
Recipients Jim.Jewett, chortos, dmascialino, eric.araujo, eric.snow, ezio.melotti, jjconti, loewis, ncoghlan, rbcollins, ubershmekel
Date 2015-03-16.02:15:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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(, then imports foo, and in between the contents of 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 change, and then someone calls linecache.getlines(

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.
Date User Action Args
2015-03-16 02:15:03rbcollinssetrecipients: + rbcollins, loewis, ncoghlan, jjconti, ezio.melotti, eric.araujo, ubershmekel, chortos, dmascialino, eric.snow, Jim.Jewett
2015-03-16 02:15:03rbcollinssetmessageid: <>
2015-03-16 02:15:03rbcollinslinkissue8087 messages
2015-03-16 02:15:01rbcollinscreate