Skip to content

Commit 024d6bc

Browse files
committed
upip: install_pkg: Use try-finally to ensure opened socket always closed.
1 parent 1bfd389 commit 024d6bc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

upip/upip.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ def install_pkg(pkg_spec, install_path):
173173
print("Installing %s %s from %s" % (pkg_spec, latest_ver, package_url))
174174
package_fname = op_basename(package_url)
175175
f1 = url_open(package_url)
176-
f2 = uzlib.DecompIO(f1, gzdict_sz)
177-
f3 = tarfile.TarFile(fileobj=f2)
178-
meta = install_tar(f3, install_path)
179-
f1.close()
176+
try:
177+
f2 = uzlib.DecompIO(f1, gzdict_sz)
178+
f3 = tarfile.TarFile(fileobj=f2)
179+
meta = install_tar(f3, install_path)
180+
finally:
181+
f1.close()
180182
del f3
181183
del f2
182184
gc.collect()

0 commit comments

Comments
 (0)