Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings

fix: unclosed file handle in evaluate_ner() when dumping metrics #597

Copy link
Copy link

Description

@rtmalikian
Issue body actions

Problem

In scispacy/train_utils.py line 29, evaluate_ner() opens a file handle for writing metrics but never closes it:

json.dump(metrics, open(dump_path, "a+"))

The open() call creates a file object that is passed directly to json.dump(). After json.dump() returns, the file handle is not explicitly closed. While CPython"s reference counting will eventually close it, this is not guaranteed on other Python implementations (PyPy, Jython) and is a resource leak.

More importantly, without explicit close/flush, the written data may not be flushed to disk immediately, which could cause data loss if the process crashes after this point.

Affected File

  • scispacy/train_utils.py line 29
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.