This repository was archived by the owner on Jun 10, 2024. It is now read-only.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixed #149.
Problem
I encountered a module-import error.
For example, if I create a project like this:
and in another project, I import
f_projectand callf()like this:It will output the correct result the first time you run the script, but when you modify the script in
f_project, for example, changef calledtof called again, and runspideragain, you will still get the result as it was. However, restartingpyspidercan reload the project.Analysis
After reading code in
\pyspider\processor\project_module.py, I think this bug was produced because pyspider usesix.exec_(code, mod.__dict__)to dynamically execute the script, and this code import a same module multiple times whenever pressing the run button. Since in Python, a module can only be imported once, any import after the first import will be ignored, so the result remains the same.Solution
I'm willing to use something like
six.moves.reload_moduleto reload the module, but it has no effect, so I just simply removed all modules matchingprojects.*(that means all modules inpyspiderproject) beforeProjectLoader.load_modulewas called. As a result, all modules in this project will be re-import, and that solved the problem.Looking forward to any better solution on solving this bug if available.