-
Notifications
You must be signed in to change notification settings - Fork 766
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
High CPU on starting pylance from get_pytest_options.py #4218
Comments
I can see it is assigned to someone. Is it open for contributions? |
I think it is via pyright |
I was having the same issue with Pylance extension at version 2023.6.0, rolling back to 2023.4.1 fixed the issue. VSCode update auto updated it to new version, extension bisect didn't help because reload window wasnt killing spawned processes. Probably related: microsoft/vscode-python#20994. |
So far I'm unable to repro this.
@rchiodo, any ideas what might be going on here? |
That code is attempting to import pytest and ask it for its configuration. If that hangs for some reason, it might cause the python process to use the CPU for a while. It should be called just once though? Is it being called multiple times? What are the arguments to the python process? |
Additionally, if you could try running this from the same environment:
And report on the output (and how long it takes). This would be what I get on my own machine:
It takes about 2 seconds to run for me in the root of my C drive, so I don't think the workspace has anything to do with it being slow. It might be the version of pytest though. |
My guess is something is misbehaving in the environment and maybe we need to have a timeout for this script running. |
So as I don't have python itself installed (my install is only through anaconda), I ran using the anaconda prompt to emulate what is by default happening in vscode. The code did exactly the same as what I observed, thread hangs at constant cpu usage.
Debugged, located issue areaAdding debug logs: print("1")
c = get_config()
print("2")
c.parse(sys.argv)
print("3")
print(f"Python classes: {c.getini('python_classes')}")
print(f"Python files: {c.getini('python_files')}")
print(f"Python functions: {c.getini('python_functions')}") Yielded
Meaning there is an issue with c.parse(sys.argv) somehow. Hope this helps. |
Thanks. It sounds like a bug in pytest that we'll just have to work around. |
@ethanh20009 do you know what version of pytest you have in that environment? |
Pytest 7.1.2 even launching pytest through anaconda cli is causing same issue. I believe root cause is in pytest init. |
Hmm, that version works for me too. I wonder if anaconda is adding extra args to sys.argv somehow. |
I've just resolved the error on my end, seems anaconda messed up pytest install. After fixing this though, it seemed to have uninstalled ipykernel which I was using for jupyter notebooks for pytorch. Maybe there's an incompatibility? I'm going to stick with commenting out the code for now because that had no affect on the ability for my code to run. |
after more debugging, I messed up my conda environment - I could no longer get my code to run at all. creating and running in a new fresh environment seemed to have solved it for me, and solved the hanging thread issue as well. Still seems odd, now running pytest --version will say I do not have the package installed. All works normally now. Sorry for the confusion. |
Thanks that's good to know. It's potentially only broken for people with environments that are broken. . |
Looks like it could be this: pytest-dev/pytest#5844 |
This issue has been fixed in prerelease version 2023.4.21, which we've just released. You can find the changelog here: CHANGELOG.md |
Environment data
Code Snippet
Repro Steps
Expected behavior
Having vscode does not cause high cpu usage.
Actual behavior
Vscode open with python extension causes constant 25% CPU usage from ghost python threads.
Temporary found solution (not a proper fix)
If I comment out from C:\Users\ethan.vscode\extensions\ms-python.vscode-pylance-2023.4.11\dist\bundled\files get_pytest_options.py
Pylance still works and the issue no longer remains for me.
I am very new to this sort of issue fixing and I know this is not a proper fix
Please advise on a proper fix for this.
Logs
Full logs attached as .txt
pylanceLog.txt
The text was updated successfully, but these errors were encountered: