Skip to content

fix: close file handles in read_full_med_mentions and read_ner_from_tsv#624

Open
Chessing234 wants to merge 1 commit into
allenai:mainfrom
Chessing234:fix/data-util-close-file-handles
Open

fix: close file handles in read_full_med_mentions and read_ner_from_tsv#624
Chessing234 wants to merge 1 commit into
allenai:mainfrom
Chessing234:fix/data-util-close-file-handles

Conversation

@Chessing234

Copy link
Copy Markdown

Problem

scispacy/data_util.py opened several files without ever closing them:

  • read_full_med_mentions() opened the train/dev/test id files inline in set comprehensions.
  • read_ner_from_tsv() iterated directly over open(cached_path(filename)).

These handles were only released by the garbage collector, which is not deterministic on non-CPython runtimes and leaks descriptors when many files are processed.

Fix

Wrap each read in a with statement so the handle is closed as soon as the read completes. Behavior is otherwise unchanged.

Fixes #599.

Made with Cursor

Wrap the id-file and tsv reads in with-statements so the handles are
closed deterministically instead of relying on GC. Fixes allenai#599.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: unclosed file handles in read_full_med_mentions() and read_ner_from_tsv()

1 participant