Skip to content

Refactor file I/O to use context managers #298

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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