New PEP: Quality Guidelines For Standard Modules

Tim Peters tim.one at home.com
Mon Jul 2 13:37:55 EDT 2001


[Courageous]
> This is inarguably and obviously bad design. The author's choice of
> an implicit singleton in this case was a great error and lacked
> even small amounts of foresight. The error here, however, was not
> the global variable. It was the implicit global singleton attached
> to contextually-dependent state.

[Skip Montanaro]
> Let's not be too hasty here.  Version 1.1 of fileinput.py is dated
> 21-Nov-97, well before threading was widespread in Python (which is
> where this stray global stuff tends to really bite you in the butt,
> the original author's example notwithstanding). ...

If you want a threadsafe fileinput reader, create an instance of the
fileinput.FileInput class explicitly.  The module global is a default
instance, catering to approximately 99.999% of expected uses:  "the main
loop" exclusively chugs over sys.argv -- which is also a shared global.  If
you use that from multiple threads simultaneously, it's not fileinput that's
nuts <0.9 wink>.

functioning-as-designed-ly y'rs  - tim





More information about the Python-list mailing list