Skip to content
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

Detect new virtual environments #7969

Merged
merged 5 commits into from
Oct 19, 2021
Merged

Detect new virtual environments #7969

merged 5 commits into from
Oct 19, 2021

Conversation

DonJayamanne
Copy link
Contributor

@DonJayamanne DonJayamanne commented Oct 19, 2021

Related to #5319

@DonJayamanne DonJayamanne requested a review from a team as a code owner October 19, 2021 19:52
@DonJayamanne DonJayamanne requested a review from rchiodo October 19, 2021 19:52
.catch((ex) => console.error('Failed to fetch controllers without cache', ex))
.finally(() => {
let timer: NodeJS.Timeout | number | undefined;
this.interpreters.onDidChangeInterpreters(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come you're not just listening to the event? This is weird. Why does it need a timer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We only care about the event after we've listed the first set of kernels
    • Else during discovery they can fire this 100s of times
    • Based on my communication with Kartik this even will get triggered when ever there are changes to an interpreter while discovering them
    • Timer is a dirty approach to throttling
    • If this event gets fired again, we cancel the previous timer & defer discovery (as thats slow)
      • (as thats slow) Note: this is hacky, better fix is to refactor all of this and do it in a more efficient manner

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So really you're just debouncing? Maybe put a comment saying how the event fires a whole bunch at the start.

this.listKernelsImplementation(resource, cancelToken)
return this.listKernelsWithCache(
workspaceFolderId,
true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discover kernelspecs in the new virtual environments as well (not sure this is required, but added that for completeness)

@@ -4,6 +4,7 @@ import { PythonEnvironment } from '../pythonEnvironments/info';
export const IInterpreterService = Symbol('IInterpreterService');
export interface IInterpreterService {
onDidChangeInterpreter: Event<void>;
onDidChangeInterpreters: Event<void>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new API from python extension

@DonJayamanne DonJayamanne removed the request for review from a team October 19, 2021 20:21
): Promise<(KernelSpecConnectionMetadata | PythonKernelConnectionMetadata)[]> {
// If we have already searched for this resource, then use that.
const result = this.kernelSpecCache.get(cacheKey);
if (result) {
if (result && !ignoreCache) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm reading this wrong. It seems backwards. The comment says if python extension is now installed, then ignore cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats correct.
What we're doing here is:

  • If python extension was not installed previously and this method was called, then we would have cached it
  • Now if we call this method again after python extensoin is installed then isPythonExtensionIstalled = true & wasPythonExtensionInstalled = false
  • In this case we should ignore the cache (i.e. if both values are the same, then no changes, & use the cache).

Happy to update with better commands ( I think you should provide some comments I could add or provide some tips on refactoring this so that its more readable to you when you look at this next time)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just rename the 'result' variable here to 'cachedResult'. Rereading it now it makes sense because on line 62 it's getting the result from the cache.

@DonJayamanne DonJayamanne requested a review from rchiodo October 19, 2021 21:50
@DonJayamanne DonJayamanne merged commit cf48a1a into main Oct 19, 2021
@DonJayamanne DonJayamanne deleted the interpreters branch October 19, 2021 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants