Skip to content

fix file descriptor leak

Bitbucket Importer requested to merge bitbucket/declined-pr-193 into branch/default

Created originally on Bitbucket by benoit-pierre (Benoit Pierre)

Changesets for this Pull Request have not been imported, because it had been already declined on Bitbucket. Marked as closed by the import user.

The issue can be seen with the following script:

#!python
#!/usr/bin/env python

import os
import sys

import openpyxl

wb = openpyxl.load_workbook(sys.argv[1], read_only=True)
ws = wb.get_sheet_by_name(wb.get_sheet_names()[0])
for row in ws.iter_rows():
    print('doing important work')
wb.close()

fd_dir = '/proc/%u/fd' % os.getpid()
for fd_name in os.listdir(fd_dir):
  print(fd_name, '-> ', end='')
  try:
    print(os.readlink('%s/%s' % (fd_dir, fd_name)))
  except FileNotFoundError:
    print()
#!shell
> python file_leak_test.py test.xlsx
doing important work
doing important work
doing important work
doing important work
doing important work
doing important work
doing important work
doing important work
doing important work
doing important work
0 -> /dev/pts/3
1 -> /dev/pts/3
2 -> /dev/pts/3
3 ->
4 -> [...]/openpyxl/test.xlsx

Merge request reports

Loading