File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed
packages/base-manager/src
python/jupyterlab_widgets/src Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -215,9 +215,13 @@ export abstract class ManagerBase implements IWidgetManager {
215
215
* If you would like to synchronously test if a model exists, use .has_model().
216
216
*/
217
217
async get_model ( model_id : string ) : Promise < WidgetModel > {
218
+ let i = 0 ;
219
+ while ( ! this . _models [ model_id ] && i < this . _sleepTimes . length ) {
220
+ new Promise ( ( r ) => setTimeout ( r , this . _sleepTimes [ i ++ ] ) )
221
+ }
218
222
const modelPromise = this . _models [ model_id ] ;
219
223
if ( modelPromise === undefined ) {
220
- throw new Error ( ' widget model not found' ) ;
224
+ throw new Error ( ` widget model ' ${ model_id } ' not found` ) ;
221
225
}
222
226
return modelPromise ;
223
227
}
@@ -874,6 +878,7 @@ export abstract class ManagerBase implements IWidgetManager {
874
878
/**
875
879
* Dictionary of model ids and model instance promises
876
880
*/
881
+ private _sleepTimes = [ 2 , 50 , 200 , 800 ] ;
877
882
private _models : { [ key : string ] : Promise < WidgetModel > } =
878
883
Object . create ( null ) ;
879
884
}
Original file line number Diff line number Diff line change @@ -802,10 +802,15 @@ function configureRendermime(
802
802
/**
803
803
* Get the widgetManager that owns the model.
804
804
*/
805
- export function getWidgetManager ( model_id : string ) : KernelWidgetManager | null {
806
- for ( const wManager of Private . kernelWidgetManagers . values ( ) ) {
807
- if ( wManager . has_model ( model_id ) ) {
808
- return wManager ;
805
+ export async function getWidgetManager (
806
+ model_id : string
807
+ ) : Promise < KernelWidgetManager | null > {
808
+ for ( const sleepTime of [ 0 , 50 , 1000 ] ) {
809
+ await new Promise ( ( r ) => setTimeout ( r , sleepTime ) ) ;
810
+ for ( const wManager of Private . kernelWidgetManagers . values ( ) ) {
811
+ if ( wManager . has_model ( model_id ) ) {
812
+ return wManager ;
813
+ }
809
814
}
810
815
}
811
816
return null ;
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ export class WidgetRenderer
73
73
return Promise . resolve ( ) ;
74
74
}
75
75
if ( ! this . _pendingManagerMessage && ! this . _managerIsSet ) {
76
- this . manager = getWidgetManager ( source . model_id ) ;
76
+ this . manager = await getWidgetManager ( source . model_id ) ;
77
77
}
78
78
this . node . textContent = `${
79
79
this . _pendingManagerMessage || model . data [ 'text/plain' ]
You can’t perform that action at this time.
0 commit comments