Skip to content

get_xml() -> ResourceWarning: Enable tracemalloc to get the object allocation traceback #801

@BrandonGel

Description

@BrandonGel

System Info

Robosuite version, Ubuntu 24.04

Information

I am receiving this warning from get_xml() in robosuite/utils/bindin_utils.py whenever get_state() is called

ResourceWarning: Enable tracemalloc to get the object allocation traceback
/home/bho36/Documents/code/FILM/./robosuite/robosuite/utils/binding_utils.py:506: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/tmpt8nu028r/model.xml' mode='r' encoding='UTF-8'>
  return open(filename).read()

My solution was to modify the code from this

    def get_xml(self):
        with TemporaryDirectory() as td:
            filename = os.path.join(td, "model.xml")
            ret = mujoco.mj_saveLastXML(filename.encode(), self._model)
            return open(filename).read()

to this.

    def get_xml(self):
        with TemporaryDirectory() as td:
            filename = os.path.join(td, "model.xml")
            ret = mujoco.mj_saveLastXML(filename.encode(), self._model)
            with open(filename) as f:
                return f.read()

Reproduction

N/A

Expected behavior

No response

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