thread conditional code

Tim Peters tim.one at home.com
Sun Apr 15 03:26:24 EDT 2001


[Just van Rossum]
> Now what about when you'd want to be compatible with systems that
> don't support the thread module?

Seems rarely a problem in practice.  The standard library has some examples,
though, chiefly tempfile.py.  On a threaded box, that needs a lock to ensure
that generated filenames are unique.  So, near the bottom of the 2.1 version,
it tries to import thread, and if that doesn't succeed it creates a
_DummyMutex class with do-nothing .acquire() and .release() methods.  Thanks
to the magic of Python not giving a rip about types <wink>, the
_ThreadSafeCounter class can then pretend it has locks everywhere.

a-platform-without-threads-is-the-same-as-a-platform-with-one-thread-ly
    y'rs  - tim





More information about the Python-list mailing list