Skip to content

Ensure we start watching environments when activating discovery component #19827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -28,15 +29,22 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato

private watchersReady?: Deferred<void>;

/**
* This can be used to initialize resources when subclasses are created.
*/
protected async activate(): Promise<void> {
await this.ensureResourcesReady();
// There is not need to wait for the watchers to get started.
this.ensureWatchersReady().ignoreErrors();
}

public async dispose(): Promise<void> {
await this.disposables.dispose();
}

public async *iterEnvs(query?: PythonLocatorQuery): IPythonEnvsIterator<I> {
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();
}

/**
Expand Down Expand Up @@ -87,7 +95,10 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato
return;
}
this.resourcesReady = createDeferred<void>();
await this.initResources();
await this.initResources().catch((ex) => {
traceError(ex);
this.resourcesReady?.reject(ex);
});
this.resourcesReady.resolve();
}

Expand All @@ -97,7 +108,10 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato
return;
}
this.watchersReady = createDeferred<void>();
await this.initWatchers();
await this.initWatchers().catch((ex) => {
traceError(ex);
this.watchersReady?.reject(ex);
});
this.watchersReady.resolve();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export abstract class FSWatchingLocator<I = PythonEnvInfo> extends LazyResourceB
private readonly watcherKind: FSWatcherKind = FSWatcherKind.Global,
) {
super();
this.activate().ignoreErrors();
}

protected async initWatchers(): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/client/pythonEnvironments/base/locators/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class WorkspaceLocators<I = PythonEnvInfo> extends LazyResourceBasedLocat

constructor(private readonly watchRoots: WatchRootsFunc, private readonly factories: WorkspaceLocatorFactory<I>[]) {
super();
this.activate().ignoreErrors();
}

public async dispose(): Promise<void> {
Expand Down