[Python-Dev] Making python C-API thread safe (try 2)

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Tue Sep 16 17:17:55 EDT 2003


On Tue, 16 Sep 2003 20:06:00 +0300, rumours say that Harri Pesonen
<fuerte at sci.fi> might have written:

>There is no object-level locking in my proposal. Just independent 
>free-threaded interpreters, which don't see the objects of other 
>interpreters at all.

What's the point in using threads then?  Threading implies easy access
to shared data.

>There could be an extra global interpreter state for shared-memory 
>object access. Accessing this would always be synchronized, but only 
>this. Python would automatically copy data from this state to 
>thread-local state and back when needed. This would require a special 
>syntax for variables in global state:

>synchronize a = "asdf"

In *this* case, POSH (or similar shared memory mechanisms) and multiple
processes should be a simpler solution.  UNIX systems have managed for
decades to work very well without any threading mechanisms.  pipe() and
fork() are quite older than threads and queues! :)

I do know the usefulness of threads, and I do use them [1].  But,
re-read what you wrote above, and please explain: what in your opinion
is the advantage of multiple threads over multiple processes in this
case?



[1] For example, I have a script that collects data over XML-RPC from
other machines in my company's network, does a little processing on the
data (mostly calculating md5 sums) and reads and writes local files;
when running on a 2x500MHz P3 Linux, I've seen it reach up to 134%
(command 'top' shows full utilisation of *one* CPU as 100%); running on
a 2x1GHz P3 W2k machine, task manager shows up to 74% (with a lower
averaging interval, peaks are easier to spot).  Think I would do better
without the GIL?
In the few cases where I would love to have "free" threading in Python
(eg an image comparison script of mine), I have already implemented the
heavy calculations in C, allowing python threads in the meanwhile.
Threads are most useful when doing mostly CPU-intensive calculations;
Python is not created for these, but it is an excellent glue language.
-- 
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.




More information about the Python-list mailing list