Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
05ddbf08
Commit
05ddbf08
authored
Apr 01, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #23838: linecache now clears the cache and returns an empty result on
MemoryError.
parents
ef2a397a
c512adc9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
7 deletions
+25
-7
Lib/linecache.py
Lib/linecache.py
+7
-4
Lib/test/test_linecache.py
Lib/test/test_linecache.py
+15
-3
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/linecache.py
View file @
05ddbf08
...
...
@@ -40,11 +40,14 @@ def getlines(filename, module_globals=None):
if
filename
in
cache
:
entry
=
cache
[
filename
]
if
len
(
entry
)
=
=
1
:
return
updatecache
(
filename
,
module_globals
)
return
cache
[
filename
][
2
]
else
:
if
len
(
entry
)
!
=
1
:
return
cache
[
filename
][
2
]
try
:
return
updatecache
(
filename
,
module_globals
)
except
MemoryError
:
clearcache
()
return
[]
def
checkcache
(
filename
=
None
):
...
...
Lib/test/test_linecache.py
View file @
05ddbf08
...
...
@@ -169,9 +169,21 @@ class LineCacheTests(unittest.TestCase):
linecache
.
lazycache
(
NONEXISTENT_FILENAME
,
globals
()))
self
.
assertEqual
(
4
,
len
(
linecache
.
cache
[
NONEXISTENT_FILENAME
]))
def
test_memoryerror
(
self
):
lines
=
linecache
.
getlines
(
FILENAME
)
self
.
assertTrue
(
lines
)
def
raise_memoryerror
(
*
args
,
**
kwargs
):
raise
MemoryError
with
support
.
swap_attr
(
linecache
,
'updatecache'
,
raise_memoryerror
):
lines2
=
linecache
.
getlines
(
FILENAME
)
self
.
assertEqual
(
lines2
,
lines
)
linecache
.
clearcache
()
with
support
.
swap_attr
(
linecache
,
'updatecache'
,
raise_memoryerror
):
lines3
=
linecache
.
getlines
(
FILENAME
)
self
.
assertEqual
(
lines3
,
[])
self
.
assertEqual
(
linecache
.
getlines
(
FILENAME
),
lines
)
def
test_main
():
support
.
run_unittest
(
LineCacheTests
)
if
__name__
==
"__main__"
:
test_
main
()
unittest
.
main
()
Misc/NEWS
View file @
05ddbf08
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Issue #23838: linecache now clears the cache and returns an empty result on
MemoryError.
- Issue #10395: Added os.path.commonpath(). Implemented in posixpath and ntpath.
Based on patch by Rafik Draoui.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment