Skip to content

Commit cc0cd4d

Browse files
committed
WIP: Hunt for open socket continues
1 parent 98f5faa commit cc0cd4d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/io/excel.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ def __init__(self, io, **kwds):
395395
# to get_filepath_or_buffer()
396396
if _is_url(self._io):
397397
io = _urlopen(self._io)
398+
should_close = True
398399
elif not isinstance(self.io, (ExcelFile, xlrd.Book)):
399-
io, _, _, _ = get_filepath_or_buffer(self._io)
400+
io, _, _, should_close = get_filepath_or_buffer(self._io)
400401

401402
if engine == 'xlrd' and isinstance(io, xlrd.Book):
402403
self.book = io
@@ -419,6 +420,12 @@ def __init__(self, io, **kwds):
419420
raise ValueError('Must explicitly set engine if not passing in'
420421
' buffer or path for io.')
421422

423+
if should_close:
424+
try:
425+
io.close()
426+
except: # noqa: flake8
427+
pass
428+
422429
def __fspath__(self):
423430
return self._io
424431

0 commit comments

Comments
 (0)