@@ -19,7 +19,7 @@ import { CancellationToken } from 'vscode-jsonrpc';
1919import { Cancellation } from '../../common/cancellation' ;
2020import { isTestExecution } from '../../common/constants' ;
2121import { traceInfo , traceWarning } from '../../common/logger' ;
22- import { createDeferred , waitForPromise } from '../../common/utils/async' ;
22+ import { sleep , waitForPromise } from '../../common/utils/async' ;
2323import * as localize from '../../common/utils/localize' ;
2424import { noop } from '../../common/utils/misc' ;
2525import { IConnection , IJupyterKernelSpec , IJupyterSession } from '../types' ;
@@ -173,24 +173,24 @@ export class JupyterSession implements IJupyterSession {
173173 }
174174
175175 private async waitForIdleOnSession ( session : Session . ISession | undefined , timeout : number ) : Promise < void > {
176- if ( session && session . kernel && session . kernel . status !== 'idle' ) {
176+ if ( session && session . kernel ) {
177177 traceInfo ( `Waiting for idle on: ${ session . kernel . id } ${ session . kernel . status } ` ) ;
178178
179- // Just listen to the event until we get to idle
180- const deferred = createDeferred < boolean > ( ) ;
181- const handler = ( _s : Session . ISession , a : Kernel . Status ) => {
182- if ( a === 'idle' ) {
183- traceInfo ( `Completed waiting for idle on: ${ session . kernel . id } ${ session . kernel . status } ` ) ;
184- deferred . resolve ( true ) ;
185- }
186- } ;
187- session . statusChanged . connect ( handler ) ;
188- const result = waitForPromise ( deferred . promise , timeout ) ;
189- session . statusChanged . disconnect ( handler ) ;
190-
191- // If that didn't work throw an exception
192- if ( result === null || ! result || ! session || ! session . kernel ) {
193- traceInfo ( `Failed waiting for idle on: ${ session . kernel . id } ${ session . kernel . status } ` ) ;
179+ // This function seems to cause CI builds to timeout randomly on
180+ // different tests. Waiting for status to go idle doesn't seem to work and
181+ // in the past, waiting on the ready promise doesn't work either. Check status with a maximum of 5 seconds
182+ const startTime = Date . now ( ) ;
183+ while ( session &&
184+ session . kernel &&
185+ session . kernel . status !== 'idle' &&
186+ ( Date . now ( ) - startTime < timeout ) ) {
187+ await sleep ( 100 ) ;
188+ }
189+
190+ traceInfo ( `Finished waiting for idle on: ${ session . kernel . id } ${ session . kernel . status } ` ) ;
191+
192+ // If we didn't make it out in ten seconds, indicate an error
193+ if ( ! session || ! session . kernel || session . kernel . status !== 'idle' ) {
194194 throw new JupyterWaitForIdleError ( localize . DataScience . jupyterLaunchTimedOut ( ) ) ;
195195 }
196196 }
0 commit comments