Basic threading questions

John Lull lull at acm.org
Mon Dec 31 14:11:09 EST 2001


I am writing a module that must be thread-friendly.  By that, I mean:

1. All operations must be thread-safe.
2. The module uses a single background thread to perform several long-running
operations. If the background thread blocks, it must do so in a way that allows
other threads to continue running while it is blocked.


I have a couple questions which I have not been able to resolve from the Python
documentation.

1. The library reference for the thread module says "Not all built-in functions
that may block waiting for I/O allow other threads to run."  Is there a list of
the built-in blocking operations that either block nicely, or do not block
nicely?  If not, how would I find out about a particular operation?

2. The Library Reference notes several operations that are not thread-safe, but
has few statements that specific things *are* thread-safe.  Can I assume that,
absent a specific statement to the contrary in the documentation, all built-in
operations (and standard library modules?) are thread-safe?  If that's too broad
a generalization, can I at least assume that the dictionary and list objects are
thread-safe, and that adding, deleting, replacing, and accessing attributes of a
class are thread-safe?

If it matters, I'm using Python 2.2.0 under Win98 and Win2K, but I'd prefer a
more general discussion of the issues involved.


Is there someplace that addresses Python-specific threading issues like these
more thoroughly?

Thanks.

Regards,
John



More information about the Python-list mailing list