multithread programming in python?

Preston Landers prestonlanders at my-deja.com
Wed Mar 29 13:32:17 EST 2000


Python includes two threading modules, assuming your Python was
configured for threads when it was built. One provides the primitives
and the other ('threading') provides higher-level access.

In general, Python relies on operating system threads unless you
specifically compile it using userspace threads.  This should offer good
enough performance for all but the most demanding applications.

Keep in mind that there are threading limitations on most platforms.
For instance, on Linux, thread creation is generally a 'slow' operation,
plus there are limitations to using more than about 300-400 threads in
an application.  Userspace threads like the MIT pthreads packages
overcome some of these limitations but are deficient in other areas.

I don't know what your application is like, but simulations typically
prefer large numbers of lightweight threads, so you might consider a
userspace thread library if you think your platform might not be up to
the task.  For instance, many functions in the Linux kernel take longer
to complete the more entries there are in the process table (every
thread is essentially a process/task in Linux).  So loading up hundreds
of active threads on the system will disproportionately slow down the
entire system.  This isn't a limitation of Python but your kernel.

There is a Stackless Python implementation (www.stackless.com) that also
implements lightweight microthreads not subject to these limitations.
Stackless is currently under development and binaries are not availible
for anything other than Win32 so far.

The company I work for uses threaded Python in a high-volume, mission
critical application.  It's working okay for us, in general.  Our
runtime environment is somewhat outdated (slackware, libc5, mit
pthreads) and we are investigating the most reliable, robust platform to
run Python threads on.

hope this helps,

---Preston Landers


In article <Pine.LNX.4.10.10003291213460.967-100000 at worf.mcnc.org>,
oliver <fwang2 at yahoo.com> wrote:
> hi,
>
> I just begin to look at python, like its clean syntax and high level
data
> type, I need to prototype a simulation which involve multiple threads
and
> timer, I wonder if I can achieve that in Python? or the kind of task
is
> not supported or suitable for python? please elaborate.
>
> thanks for help
>
> oliver
>
>
--
|| Preston Landers <prestonlanders at my-deja.com> ||


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list