You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically if you create a singleton via its constructor it does not check for other instances.
This is problematic as Applications are SingletonConfigurable and can have subapps, so inherently traitlets is unsound. The order in which you create those will change the result of Application.instance() I believe.
Singletons are not strictly enforced - you can have many instances of a given singleton class, but the instance() method will always return the same one.
I'm not sure about the ordering issue, normally SubApp.instance() would raise if another subapp is already instantiated. See for example related discussion in #474 and the (inactive) PR which aims to handles the case of a non-singleton subcommand.
Edit: I do agree the docs could use further clarification on this, it definitely is a bit confusing and the docstring for SingletonConfigurable is misleading as per the current design. But I think trying to change Application.__init__() to be truly a singleton would break a significant amount of downstream code.
Activity
azjps commentedon Sep 19, 2023
This is intentional I believe, the singleton API is only accessed via the
instance() / clear_instance() / instantiated()methods: https://traitlets.readthedocs.io/en/stable/config.html#the-main-conceptsThere's an example in the docs under
examples/docs/multiple_apps.py, although I added it based on related threads in this tracker.I'm not sure about the ordering issue, normally
SubApp.instance()would raise if another subapp is already instantiated. See for example related discussion in #474 and the (inactive) PR which aims to handles the case of a non-singleton subcommand.Edit: I do agree the docs could use further clarification on this, it definitely is a bit confusing and the docstring for
SingletonConfigurableis misleading as per the current design. But I think trying to changeApplication.__init__()to be truly a singleton would break a significant amount of downstream code.Carreau commentedon Sep 19, 2023
Yeah, the problem is I believe that a few places are not using
.instance()which can lead to assumptions about having singletons.