This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
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_project
and 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 called
tof called again
, and runspider
again, you will still get the result as it was. However, restartingpyspider
can 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_module
to reload the module, but it has no effect, so I just simply removed all modules matchingprojects.*
(that means all modules inpyspider
project) beforeProjectLoader.load_module
was 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.