This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients SilentGhost, lisroach, thatch, vstinner, yselivanov
Date 2019-06-17.21:53:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560808419.07.0.514458584791.issue37166@roundup.psfhosted.org>
In-reply-to
Content
inspect.getsource() starts with linecache.checkcache(file) which if the file modification time changed or if the file size changed. Using regular files on disk, I don't see how this bug is possible:


$ cat x.py 
import inspect
import os
import linecache






def foo(): pass

filename = __file__
linecache.getlines(filename)

if 1:
    stat = os.stat(filename)
    atime = stat.st_atime
    mtime = stat.st_mtime
    with open(filename, "w+") as fp:
        lines = [line for line in fp if line.strip()]
        fp.seek(0)
        fp.writelines(lines)
    os.utime(filename, (atime, mtime))

print(inspect.getsource(foo))

vstinner@apu$ /bin/cp x.py y.py; ./python y.py
Traceback (most recent call last):
  File "y.py", line 25, in <module>
  File "/home/vstinner/prog/python/master/Lib/inspect.py", line 985, in getsource
    lines, lnum = getsourcelines(object)
  File "/home/vstinner/prog/python/master/Lib/inspect.py", line 967, in getsourcelines
    lines, lnum = findsource(object)
  File "/home/vstinner/prog/python/master/Lib/inspect.py", line 798, in findsource
    raise OSError('could not get source code')
OSError: could not get source code


Does this bug only affect Facebook who use "compile the application into an executable package (.par)"?
https://github.com/python/cpython/pull/13850#pullrequestreview-249815779
History
Date User Action Args
2019-06-17 21:53:39vstinnersetrecipients: + vstinner, SilentGhost, thatch, yselivanov, lisroach
2019-06-17 21:53:39vstinnersetmessageid: <1560808419.07.0.514458584791.issue37166@roundup.psfhosted.org>
2019-06-17 21:53:39vstinnerlinkissue37166 messages
2019-06-17 21:53:38vstinnercreate