Skip to content

Commit

Permalink
MAINT: fixes #1652
Browse files Browse the repository at this point in the history
add close()
  • Loading branch information
François Boulogne committed Feb 4, 2016
1 parent 056028d commit 942fec2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions skimage/io/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def file_or_url_context(resource_name):
"""Yield name of file from the given resource (i.e. file or url)."""
if is_url(resource_name):
_, ext = os.path.splitext(resource_name)
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:
# Here, we need to handle the file destruction by ourself
try:
f = tempfile.NamedTemporaryFile(delete=False, suffix=ext)
u = urlopen(resource_name)
f.write(u.read())
try:
f.close()
yield f.name
finally:
os.remove(f.name)
Expand Down

0 comments on commit 942fec2

Please sign in to comment.