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

error is raised at for _name, _value in list(globals().items()): in yapf_third_party/_ylib2to3/pgen2/token.py #1118

Closed
eunwoosh opened this issue Jul 10, 2023 · 3 comments · Fixed by #1150

Comments

@eunwoosh
Copy link

eunwoosh commented Jul 10, 2023

Hi, I got an error when importing yapf whose version is 0.40.1
When the yapf is imported, yapf_third_party/_ylib2to3/pgen2/token.py is executed
and then error is raised as below.
image
I think it occurs to other people also scipy/scipy#11479
Something weird is it appears not in all cases.
It can be solved easily if for _name, _value in list(globals().items()): is changed to for _name, _value in list(globals().copy().items()):.
Could you fix this bug?

@bwendling
Copy link
Member

Please add a code snippet that replicates this error.

@eunwoosh
Copy link
Author

I'm not using yapf directly and this error is raised only if some conditions are meet (I don't know which condition it is).
And, It's quite hard to setup exactly same environment as mine, so please allow for providing code similar to my condition.
Here is the code.

import importlib
import multiprocessing as mp


def test():
    print("import start")
    importlib.import_module("yapf.yapflib.yapf_api")
    print("import end")

def main():
    spawn_mp = mp.get_context("spawn")

    p = spawn_mp.Process(target=test)
    p.start()
    p.join()

if __name__ == "__main__":
    main()

@Spitfire1900
Copy link
Contributor

Unable to reproduce

kyle@mainstay:~/Repos$ pipx run --no-cache yapf <<EOF 
import importlib
import multiprocessing as mp


def test():
    print("import start")
    importlib.import_module("yapf.yapflib.yapf_api")
    print("import end")

def main():
    spawn_mp = mp.get_context("spawn")

    p = spawn_mp.Process(target=test)
    p.start()
    p.join()

if __name__ == "__main__":
    main()
EOF
⚠️  yapf is already on your PATH and installed at /home/kyle/.local/bin/yapf. Downloading and running anyway.
import importlib
import multiprocessing as mp


def test():
    print("import start")
    importlib.import_module("yapf.yapflib.yapf_api")
    print("import end")


def main():
    spawn_mp = mp.get_context("spawn")

    p = spawn_mp.Process(target=test)
    p.start()
    p.join()


if __name__ == "__main__":
    main()
kyle@mainstay:~/Repos$ 

bwendling pushed a commit that referenced this issue Sep 25, 2023
Fixes #1118. Use a copy of globals() rather than a direct reference.
This did not appear to impact the time of tests
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 a pull request may close this issue.

3 participants