Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceWarning for unclosed filestream on svd_data.zip #1630

Open
edcloudcycle opened this issue Oct 11, 2023 · 0 comments
Open

ResourceWarning for unclosed filestream on svd_data.zip #1630

edcloudcycle opened this issue Oct 11, 2023 · 0 comments

Comments

@edcloudcycle
Copy link

Hi.
Installed the latest version today and noticed something I hadn't seen before. Maybe not due to an update but perhaps a change in where the default pack comes from on my setup.

sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='C:\\WorkingDir\\tm_fct_calibration\\.venv\\Lib\\site-packages\\pyocd\\debug\\svd\\svd_data.zip'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Looking into it when a board is created as part of a session and the memory map is created a zip stream seems to be made here:

class SVDFile(object):
    @classmethod

    def from_builtin(cls, svd_name):

        try:
            zip_ref = importlib_resources.files("pyocd").joinpath(BUILTIN_SVD_DATA_PATH)
            zip_stream = zip_ref.open('rb')
            zip = zipfile.ZipFile(zip_stream, 'r')
            return SVDFile(zip.open(svd_name))
        except (KeyError, FileNotFoundError, zipfile.BadZipFile) as err:
            from ...core.session import Session
            LOG.warning("unable to open builtin SVD file: %s", err, exc_info=Session.get_current().log_tracebacks)
            return None

But it is not clear to me where this reference is closed so maybe that is what generates the warning. I can see the session is closed when my application exits. My usage is:

with ConnectHelper.session_with_chosen_probe(blocking=False) as session:

            board = session.board
            target = board.target
            flash = target.memory_map.get_boot_memory()

            # Load firmware into device.
            FileProgrammer(session).program(filename)

            # Flash a single phrase without erasing to set the serial number
            flasher = Flash(target, flash.algo)
            flasher.region = flash
            flasher.init(operation=Flash.Operation.PROGRAM)

            flasher.program_phrase(address=0x10001080, bytes=[serial_lsb, serial_msb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])

            # Reset, run.
            target.reset_and_halt()
            target.resume()

Thanks

Ed

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

No branches or pull requests

1 participant