@@ -334,9 +334,10 @@ export class WidgetModel extends Backbone.Model {
334
334
if ( this . comm !== void 0 ) {
335
335
if ( msg . content . execution_state === 'idle' ) {
336
336
this . _pending_msgs -- ;
337
+ // Sanity check for logic errors that may push this below zero.
337
338
if ( this . _pending_msgs < 0 ) {
338
339
console . error (
339
- `Pending messages < 0 (=${ this . _pending_msgs } ), which is unexpected`
340
+ `Jupyter Widgets message throttle: Pending messages < 0 (=${ this . _pending_msgs } ), which is unexpected. Resetting to 0 to continue. `
340
341
) ;
341
342
this . _pending_msgs = 0 ; // do not break message throttling in case of unexpected errors
342
343
}
@@ -553,17 +554,18 @@ export class WidgetModel extends Backbone.Model {
553
554
return '' ;
554
555
}
555
556
try {
556
- callbacks . iopub = callbacks . iopub || { } ;
557
- if ( callbacks . iopub . previouslyUsedByJupyterWidgets === undefined ) {
558
- // Do not break other code that also wants to listen to status updates
559
- callbacks . iopub . statusPrevious = callbacks . iopub . status ;
560
- }
561
- // else callbacks.iopub.status is the old handler, that we should not reuse
562
- callbacks . iopub . previouslyUsedByJupyterWidgets = true ;
557
+ // Make a 2-deep copy so we don't modify the caller's callbacks object.
558
+ callbacks = {
559
+ shell : { ...callbacks . shell } ,
560
+ iopub : { ...callbacks . iopub } ,
561
+ input : callbacks . input ,
562
+ } ;
563
+ // Save the caller's status callback so we can call it after we handle the message.
564
+ const statuscb = callbacks . iopub . status ;
563
565
callbacks . iopub . status = ( msg : KernelMessage . IStatusMsg ) : void => {
564
566
this . _handle_status ( msg ) ;
565
- if ( callbacks . iopub . statusPrevious ) {
566
- callbacks . iopub . statusPrevious ( msg ) ;
567
+ if ( statuscb ) {
568
+ statuscb ( msg ) ;
567
569
}
568
570
} ;
569
571
0 commit comments