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

Fix environment cache regression #1238

Merged
merged 1 commit into from
Dec 15, 2018
Merged

Fix environment cache regression #1238

merged 1 commit into from
Dec 15, 2018

Conversation

bet4it
Copy link
Contributor

@bet4it bet4it commented Oct 14, 2018

Currently, if VIRTUAL_ENV is empty, which will occur when we don't use a virtual environment, the get_cached_default_environment will always clear the cache.
I think it's a regression caused by 862f611.

@davidhalter
Copy link
Owner

I agree. This attempt at fixing this does use the cache even more. I think we just need to check if $VIRTUALENV is set and then act.

@bet4it
Copy link
Contributor Author

bet4it commented Oct 14, 2018

The code may seem to be weird, but I have tested it and the cache is really used.

@davidhalter
Copy link
Owner

Yes, but only if $VIRTUALENV is not set.

@bet4it
Copy link
Contributor Author

bet4it commented Oct 21, 2018

Why? get_default_environment will call get_default_environment and get_default_environment will still call os.environ.get('VIRTUAL_ENV').
And I have test it in virtual environment and it works.

@davidhalter
Copy link
Owner

davidhalter commented Oct 21, 2018

My logic was a bit off, but what I said still applies. If VIRTUALENV is set, you will always create a new environment.

@bet4it
Copy link
Contributor Author

bet4it commented Oct 22, 2018

I have dug into the code and found what's wrong with me. Apologize for my reckless.
We can surely change the code like what you said, but I think we can don't create subprocess until _get_subprocess is called in Environment class like what SameEnvironment class has done?
If there are still something I have ignored, let me know.

@bet4it
Copy link
Contributor Author

bet4it commented Nov 1, 2018

Sorry, I find that I'm wrong again.
Totally rewrite the commit as what you said.

@bet4it
Copy link
Contributor Author

bet4it commented Nov 2, 2018

Should we consider the situation that people switch virtual environment to real environment?

@heftig
Copy link

heftig commented Nov 23, 2018

This was my attempt:

def get_cached_default_environment():
    return _get_cached_default_environment(os.environ.get('VIRTUAL_ENV'))


@time_cache(seconds=10 * 60)  # 10 Minutes
def _get_cached_default_environment(_venv):
    return get_default_environment()

Much simpler, IMO.

@ChanningBJ
Copy link

This fix sloved my problem

@blueyed
Copy link
Contributor

blueyed commented Nov 26, 2018

@bet4it
Should we go with the patch from @heftig (which is applied to python-jedi in Arch Linux already)?

@davidhalter
Copy link
Owner

The solution of @heftig has the issue that it doesn't clean the cache if it encounters something different. I don't really like that (because that would mean keeping around processes longer than necessary).

The only remaining issue with this PR is that it does compare with executable instead of _start_executable (they don't need to be the same).

@Yevgnen
Copy link

Yevgnen commented Dec 1, 2018

Any news on this ?

@davidhalter davidhalter merged commit 76417cc into davidhalter:master Dec 15, 2018
@davidhalter
Copy link
Owner

@bet4it and everyone else: Thanks a lot for your patience. I was very demotivated lately to visit the issue tracker. Therefore this was lingering around here way longer than it should have. Sorry! I guess I will have a bit more motivation once I have the typeshed stuff merged.

There's this one small issue that I'm going to fix, but you don't need to care anymore.

@davidhalter
Copy link
Owner

I actually just realized that my criticism was wrong anyway. This could have been merged way sooner...

@davidhalter
Copy link
Owner

I only just realized how bad this issue was. Big sorry for that. I therefore did a release immediately. (0.13.2)

@CarlQLange
Copy link

CarlQLange commented Jan 8, 2019

No need for sorry, @davidhalter! Jedi is a great tool and everybody who uses it appreciates all the hard work you put in!

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.

7 participants