简体   繁体   中英

Python Code Momentarily Working only when pyc files change

I'm experiencing a very odd issue. I've changed a bit of python code from one revision to the next and it seemed to break the code (despite passing tests). When I went and added a debug statement, the code began working fine. Trying it again made it fail. After experimenting, I realized that it would work on one run only after the pyc file was changed or deleted. What?? Has anyone else experienced this? Any ideas to fix this?

tldr: Code only works right after pyc changed or deleted and then stops working.

EDIT: It seems to be the issue is the pyc file by itself. I compiled the pyc files without running the code and tried running it and it didn't work. I did some research and I THINK that the way python creates these pyc is that when I try to run it, it loads it into the environment and then creates the pyc. Which means that it works when it's loaded in from source, but fails when loaded in from pyc.

perhaps your PYC file is being updated by some sort of sync, written after its been compiled, then python runs the PYC instead of recompiling the PY.

Try this:

>python --help
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM