VS code live update event


I am writing an extension so that I can communicate with a simulated unitree go1’s quadruped controller via UDP. To do this I have used the A1 extension example with which I spawn a thread at init to run the udp socket which then receives (or doesnt) commands that update the robots controller.

However, whenever I save a change in vs code the extension updates and will not load correctly because the UDP port is still in use. I have tried closing the thread and killing the UDPs while loop with a variable stored in a shutdown signal (that is updated in post_clear, post_reset, world_cleanup) but the variable is never updated.
I also tried to create a shutdown event subscription as per the docs but that also does not fire when vs code updates.

What is exactly happening when vs code live upodates the extension? is there an event I can subscribe to so I can gracefully shutdown my UDP? or any other way to accomplish this?


Hi @stefan.podg. @toni.sm, another community member has done something similar with sockets. I would look at how he’s shutting down: https://github.com/Toni-SM/semu.misc.vscode/blob/main/exts/semu.misc.vscode/semu/misc/vscode/scripts/extension.py
Hot reloading watches all py files in your extension and then basically does this:

  1. Calls shutdown on your extension.
  2. Reloads the python files
  3. Enables your extension.

Putting your server/socket shutdown code in the extension’s on_shutdown event should be sufficient. I think Toni also listens for app shutdown events to get a clean shutdown when the app closes.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.