Skip to content

Refactor the Meshtastic TCP pub/sub example to ensure proper resource cleanup and clearer exception handling.#899

Open
dim5x wants to merge 1 commit intomeshtastic:masterfrom
dim5x:master
Open

Refactor the Meshtastic TCP pub/sub example to ensure proper resource cleanup and clearer exception handling.#899
dim5x wants to merge 1 commit intomeshtastic:masterfrom
dim5x:master

Conversation

@dim5x
Copy link

@dim5x dim5x commented Feb 5, 2026

What changed:

  • Wrapped the TCP interface lifecycle in a try / finally block to guarantee that TCPInterface.close() is always called.
  • Initialized iface to None to safely handle failures during interface creation.
  • Replaced sys.exit(1) with re-raising the exception to preserve the original traceback.
  • Simplified imports by importing TCPInterface directly.
  • Kept the example behavior and public API unchanged.

Why:

  • The original example never reached iface.close() due to the infinite loop and could leave the TCP connection open when interrupted or when an exception occurred.
  • Using finally ensures deterministic cleanup and makes the example safer and easier to reason about, especially for users copying it into their own scripts.
  • Re-raising the exception provides better diagnostics while still allowing finally to run.

Behavior impact:

  • No functional changes to the demo logic.
  • Improved reliability and correctness on errors or interruptions.
  • More idiomatic Python resource handling.

@CLAassistant
Copy link

CLAassistant commented Feb 5, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants