How to force disable an ext, or force reload

Sometimes when developing an extension, it breaks something. Then, it is not possible to unload the extension (e.g. I can still see my custom UI buttons). The console shows the image that continuously prints this error. I know it came from this one update subscriber function, so I commented out the subscriber, but the error still showed. Then, I even commented out the function itself, and again the error shows an error on lines that are not even active. So, its not reloading.

The script is definitely not the problem, because I don’t change the script at all, close kit, relaunch it, and then open the extension again and it works.

*update: question remains, but I found that there is an issue with how the _on_update function gets overridden when using self._update_sub = omni.kit.app.get_app().get_update_event_stream().create_subscription_to_pop( self._on_update, name="omni.physx demo update hack" ).
I noticed that, for example, if I add a print statement in self._on_update, it will print to the console. However, if I change the data that is printing, it adds that print statement instead of replacing it. So it seems like there is something that is appending the function that is changed, instead of replacing it.

Unfortunately there are situation where you basically have to restart app. The reason we use that pattern self._update_sub = is to avoid it as much as possible. Basically subscription lifetime is associated with this object self._update_sub and when it gets destroyed subscription destroyed too. You can often find in code that we explicitly make sure those self._update_sub = None are called from shutdown. It is easy to get into circular dependencies with python which go into C++ code and then back to python, GC can’t resolve them automatically (no information) and objects leave hanging.

So is there a reference counter to any class that inherits omni.ext.IExt that is maintained for the lifetime of the kit application once it is loaded? I think the explanation you gave above would go well in the architecture explanation, or at least as a Note under item 6 Architecture — Omniverse Kit 102.1.2+release.46667.2027b54e.teamcity documentation that mentions Note: Not all parts of an extension can be reloaded, for more details, see Extension Enabling/Disabling which would link to your (more) explanation Extensions — Omniverse Kit 102.1.2+release.46667.2027b54e.teamcity documentation

@anovoselov So I found a related problem to this and my other comment.

I may have read it somewhere, but it seems that the import method is handled differently by omniverse. For example, relative package imports like:

from .simulation import mymod

do not get reloaded. However, importing the same file as:

from omni.myext.simulation import mymod

this does get reloaded.