Skip to content

Commit 819fb22

Browse files
committed
Added back linecache.clearcache
1 parent bba485e commit 819fb22

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

line_profiler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def show_func(filename, start_lineno, func_name, timings, unit, stream=None):
155155
linenos.append(lineno)
156156
print >>stream, "Total time: %g s" % (total_time * unit)
157157
if os.path.exists(filename) or filename.startswith("<ipython-input-"):
158+
if os.path.exists(filename):
159+
# Clear the cache to ensure that we get up-to-date results.
160+
linecache.clearcache()
158161
all_lines = linecache.getlines(filename)
159162
sublines = inspect.getblock(all_lines[start_lineno-1:])
160163
else:
@@ -190,8 +193,7 @@ def show_text(stats, unit, stream=None):
190193
print >>stream, 'Timer unit: %g s' % unit
191194
print >>stream, ''
192195
for (fn, lineno, name), timings in sorted(stats.items()):
193-
show_func(fn, lineno, name, stats[fn, lineno, name], unit,
194-
stream=stream)
196+
show_func(fn, lineno, name, stats[fn, lineno, name], unit, stream=stream)
195197

196198
# A %lprun magic for IPython.
197199
def magic_lprun(self, parameter_s=''):

0 commit comments

Comments
 (0)