-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid using a global force_load widget
- Loading branch information
1 parent
2638b7b
commit 5289093
Showing
4 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ipywidgets import Widget | ||
import threading | ||
|
||
|
||
lock = threading.Lock() | ||
|
||
|
||
def singleton(WidgetClass, **kwargs): | ||
# find a 'shared' instance (singleton) to avoid creating | ||
# too many widgets. In contexts where self.widgets is not | ||
# a global dict, this allows different users/context to | ||
# have a singleton without sharing the widget | ||
with lock: | ||
if hasattr(Widget, "widgets"): | ||
# pre 8.0 | ||
all_widgets = Widget.widgets | ||
if hasattr(Widget, "widgets"): | ||
all_widgets = Widget._widgets | ||
else: | ||
|
||
for widget in all_widgets.values(): | ||
if isinstance(widget, WidgetClass): | ||
return widget | ||
return WidgetClass(**kwargs) |