diff --git a/src/client/pythonEnvironments/base/locators/common/resourceBasedLocator.ts b/src/client/pythonEnvironments/base/locators/common/resourceBasedLocator.ts index 451df3fe38a1..2a524ad7d28f 100644 --- a/src/client/pythonEnvironments/base/locators/common/resourceBasedLocator.ts +++ b/src/client/pythonEnvironments/base/locators/common/resourceBasedLocator.ts @@ -4,6 +4,7 @@ import { IDisposable } from '../../../../common/types'; import { createDeferred, Deferred } from '../../../../common/utils/async'; import { Disposables } from '../../../../common/utils/resourceLifecycle'; +import { traceError } from '../../../../logging'; import { PythonEnvInfo } from '../../info'; import { IPythonEnvsIterator, Locator, PythonLocatorQuery } from '../../locator'; @@ -28,15 +29,22 @@ export abstract class LazyResourceBasedLocator extends Locato private watchersReady?: Deferred; + /** + * This can be used to initialize resources when subclasses are created. + */ + protected async activate(): Promise { + await this.ensureResourcesReady(); + // There is not need to wait for the watchers to get started. + this.ensureWatchersReady().ignoreErrors(); + } + public async dispose(): Promise { await this.disposables.dispose(); } public async *iterEnvs(query?: PythonLocatorQuery): IPythonEnvsIterator { - await this.ensureResourcesReady(); + await this.activate(); yield* this.doIterEnvs(query); - // There is not need to wait for the watchers to get started. - this.ensureWatchersReady().ignoreErrors(); } /** @@ -87,7 +95,10 @@ export abstract class LazyResourceBasedLocator extends Locato return; } this.resourcesReady = createDeferred(); - await this.initResources(); + await this.initResources().catch((ex) => { + traceError(ex); + this.resourcesReady?.reject(ex); + }); this.resourcesReady.resolve(); } @@ -97,7 +108,10 @@ export abstract class LazyResourceBasedLocator extends Locato return; } this.watchersReady = createDeferred(); - await this.initWatchers(); + await this.initWatchers().catch((ex) => { + traceError(ex); + this.watchersReady?.reject(ex); + }); this.watchersReady.resolve(); } } diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/fsWatchingLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/fsWatchingLocator.ts index df9275c0eee4..bccc705aa818 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/fsWatchingLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/fsWatchingLocator.ts @@ -84,6 +84,7 @@ export abstract class FSWatchingLocator extends LazyResourceB private readonly watcherKind: FSWatcherKind = FSWatcherKind.Global, ) { super(); + this.activate().ignoreErrors(); } protected async initWatchers(): Promise { diff --git a/src/client/pythonEnvironments/base/locators/wrappers.ts b/src/client/pythonEnvironments/base/locators/wrappers.ts index 9313ade20218..fbc21fb44b21 100644 --- a/src/client/pythonEnvironments/base/locators/wrappers.ts +++ b/src/client/pythonEnvironments/base/locators/wrappers.ts @@ -59,6 +59,7 @@ export class WorkspaceLocators extends LazyResourceBasedLocat constructor(private readonly watchRoots: WatchRootsFunc, private readonly factories: WorkspaceLocatorFactory[]) { super(); + this.activate().ignoreErrors(); } public async dispose(): Promise {