Can we have a dirt-simple example of the expected behaviour?
For example, suppose I have:
# module spam.py
# Simulate some work:
import time
time.sleep(10)
print("spam loaded")
# module eggs.py
import spam
print("imports done")
Now I know that this example goes against the recommendation to avoid side-effects during module import, but I think that showing side-effects may be the easiest way to see
- what this feature does;
- and why you make that recommendation.
What normally happens is that when I run python eggs.py
, it takes 10 seconds to do the work before I see any output:
spam loaded
imports done
But with this new feature, python -L eggs.py
, it will load almost instantly, the work will never get done, and the only output will be:
imports done
Is this correct?
But if I change eggs.py to this instead:
# module eggs.py
import spam
print("imports done")
spam # Any reference to the module is enough to load it.
I get this, with comments interspersed:
imports done # appears immediately
# ten seconds while the work is done
spam imported
Is my understanding correct?
I think the PEP could do with something like this demonstrating the behaviour. Especially if I have got it wrong! If I got it right, feel free to steal my example if you like it
I also think the implementation section should have at least a high-level overview of how this magical behaviour is implemented, not just âread the source of Cinderâ