Skip to content

Commit 2f4e9a0

Browse files
author
Kartik Raj
authored
Ensure we start watching environments when activating discovery component (microsoft#19827)
Ensure we start watchers and create workspace related objects when activating discovery component
1 parent 2ef2db4 commit 2f4e9a0

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/client/pythonEnvironments/base/locators/common/resourceBasedLocator.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { IDisposable } from '../../../../common/types';
55
import { createDeferred, Deferred } from '../../../../common/utils/async';
66
import { Disposables } from '../../../../common/utils/resourceLifecycle';
7+
import { traceError } from '../../../../logging';
78
import { PythonEnvInfo } from '../../info';
89
import { IPythonEnvsIterator, Locator, PythonLocatorQuery } from '../../locator';
910

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

2930
private watchersReady?: Deferred<void>;
3031

32+
/**
33+
* This can be used to initialize resources when subclasses are created.
34+
*/
35+
protected async activate(): Promise<void> {
36+
await this.ensureResourcesReady();
37+
// There is not need to wait for the watchers to get started.
38+
this.ensureWatchersReady().ignoreErrors();
39+
}
40+
3141
public async dispose(): Promise<void> {
3242
await this.disposables.dispose();
3343
}
3444

3545
public async *iterEnvs(query?: PythonLocatorQuery): IPythonEnvsIterator<I> {
36-
await this.ensureResourcesReady();
46+
await this.activate();
3747
yield* this.doIterEnvs(query);
38-
// There is not need to wait for the watchers to get started.
39-
this.ensureWatchersReady().ignoreErrors();
4048
}
4149

4250
/**
@@ -87,7 +95,10 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato
8795
return;
8896
}
8997
this.resourcesReady = createDeferred<void>();
90-
await this.initResources();
98+
await this.initResources().catch((ex) => {
99+
traceError(ex);
100+
this.resourcesReady?.reject(ex);
101+
});
91102
this.resourcesReady.resolve();
92103
}
93104

@@ -97,7 +108,10 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato
97108
return;
98109
}
99110
this.watchersReady = createDeferred<void>();
100-
await this.initWatchers();
111+
await this.initWatchers().catch((ex) => {
112+
traceError(ex);
113+
this.watchersReady?.reject(ex);
114+
});
101115
this.watchersReady.resolve();
102116
}
103117
}

src/client/pythonEnvironments/base/locators/lowLevel/fsWatchingLocator.ts

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export abstract class FSWatchingLocator<I = PythonEnvInfo> extends LazyResourceB
8484
private readonly watcherKind: FSWatcherKind = FSWatcherKind.Global,
8585
) {
8686
super();
87+
this.activate().ignoreErrors();
8788
}
8889

8990
protected async initWatchers(): Promise<void> {

src/client/pythonEnvironments/base/locators/wrappers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class WorkspaceLocators<I = PythonEnvInfo> extends LazyResourceBasedLocat
5959

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

6465
public async dispose(): Promise<void> {

0 commit comments

Comments
 (0)