Message345921
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 |
|
Date |
User |
Action |
Args |
2019-06-17 21:53:39 | vstinner | set | recipients:
+ vstinner, SilentGhost, thatch, yselivanov, lisroach |
2019-06-17 21:53:39 | vstinner | set | messageid: <1560808419.07.0.514458584791.issue37166@roundup.psfhosted.org> |
2019-06-17 21:53:39 | vstinner | link | issue37166 messages |
2019-06-17 21:53:38 | vstinner | create | |
|