Skip to content

Add support for importlib.reload(module) ? #10481

@jbrelwof

Description

@jbrelwof

Should support for the functionality of importlib.reload (possibly under a different name) be added to CircuitPython?

There is no importlib module for CircuitPython, therefore "normal" python reloading is not available. I have a pure-python (no firmware/C level changes required) working proof-of-concept implementation here

Since dynamic module reloading isn't exactly a beginner-friendly technique, and it doesn't take a lot of code to provide a decent basic reload implementation for CircuitPython (my current implementation is less than 90 lines - nearly half of which is comments and white space), the main point of this feature request is to discuss whether it even makes sense to provide reload functionality in the basic CircuitPython distributions. It could be provided

  • as part of the "core" CircuitPython firmware (frozen .mpy?)
  • in one of the bundles (adafruit / community)
  • as a "go copy this if you need it" guide

While the autoreload support in CircuitPython provides similar benefits for simple projects and is certainly more predictable / beginner-friendly, there are cases where "normal" reload functionality can be more efficient. One specific use case is modifying behavior of routed REST calls to an adafruit_httpserver.Server. This can dramatically speed up development for internals, diagnostics, and experimentation by removing the need to restart, reconnect wifi, fire up the web server, and wait till your project gets back to the state you were working with before...

Note that the del sys.modules[name] followed by __import__( name ) approach only mostly reloads a module - it falls short of the "normal" reload functionality in some very significant ways

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy