Skip to content

Refactor file I/O to use context managers #298

@avinxshKD

Description

@avinxshKD

Been going through cwrap.py and concore.py and noticed we're opening files without context managers in a bunch of places. Lines like:

apikey=open(concore.inpath+'1/concore.apikey',newline=None).readline().rstrip()

and

infile = open(inpath+str(port)+"/"+name);
ins = infile.read()

While CPython's GC usually handles this, it's not guaranteed especially if something crashes or throws an exception before we finish reading. Plus in cwrap.py there are open calls happening repeatedly in loops which could leak descriptors if things go wrong.

Would be good to refactor these to use with open(...) as f: statements. Not super urgent since it's working now, but it's the right way to handle resources in Python and prevents potential issues down the line.

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