Skip to content

Use Python finalizers everywhere - #11409

Draft
tannewt wants to merge 4 commits into
adafruit:mainfrom
tannewt:remove_never_reset
Draft

tannewt wants to merge 4 commits into
adafruit:mainfrom
tannewt:remove_never_reset

Conversation

@tannewt

@tannewt tannewt commented Sep 16, 2026

Copy link
Copy Markdown
Member

Remove the never_reset concept and replace it with Python finalizers to enable automatic hardware cleanup through garbage collection.

Key changes:

  • Add finalizers to digitalio.DigitalInOut, keypad objects, and rp2pio.StateMachine
  • Restructure cleanup flow in main.c to run GC finalization
  • Remove all never_reset tracking (pin bitmasks, device flags, object flags)
  • Remove bulk reset functions (reset_uart, reset_rp2pio_statemachine)
  • Simplify reset_port() to only port-wide cleanup
  • Remove never_reset declarations from shared-bindings headers
  • Remove never_reset calls from shared-module display drivers

Objects now use mp_obj_malloc_with_finaliser() and have del methods that call deinit(). Hardware resources are automatically freed when objects are garbage collected or explicitly deinit only.

Fixes #8960

Remove the never_reset concept and replace it with Python finalizers to
enable automatic hardware cleanup through garbage collection.

Key changes:
- Add finalizers to digitalio.DigitalInOut, keypad objects, and rp2pio.StateMachine
- Restructure cleanup flow in main.c to run GC finalization
- Remove all never_reset tracking (pin bitmasks, device flags, object flags)
- Remove bulk reset functions (reset_uart, reset_rp2pio_statemachine)
- Simplify reset_port() to only port-wide cleanup
- Remove never_reset declarations from shared-bindings headers
- Remove never_reset calls from shared-module display drivers

Objects now use mp_obj_malloc_with_finaliser() and have __del__ methods
that call deinit(). Hardware resources are automatically freed when objects
are garbage collected or explicitly deinit only.

Fixes micropython#8960
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

Successfully merging this pull request may close these issues.

Rework peripheral reset and always use finalizers

1 participant