mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-14 11:18:06 +08:00
MAINT: fixes #1652
add close() Stephans solution close file before remove comment
This commit is contained in:
+4
-3
@@ -24,10 +24,11 @@ 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:
|
||||
u = urlopen(resource_name)
|
||||
f.write(u.read())
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:
|
||||
u = urlopen(resource_name)
|
||||
f.write(u.read())
|
||||
# f must be closed before yielding
|
||||
yield f.name
|
||||
finally:
|
||||
os.remove(f.name)
|
||||
|
||||
Reference in New Issue
Block a user