STINNER Victor <[email protected]> added the comment:
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
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37166>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com