Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12589 > unrolled thread

Re: Threads in Python

Started byCameron Simpson <cs@zip.com.au>
First post2011-09-02 08:43 +1000
Last post2011-09-02 08:43 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Threads in Python Cameron Simpson <cs@zip.com.au> - 2011-09-02 08:43 +1000

#12589 — Re: Threads in Python

FromCameron Simpson <cs@zip.com.au>
Date2011-09-02 08:43 +1000
SubjectRe: Threads in Python
Message-ID<mailman.671.1314916996.27778.python-list@python.org>
On 01Sep2011 15:27, Stephen Hansen <me+list/python@ixokai.io> wrote:
| On 9/1/11 2:45 PM, George Kovoor wrote:
| > Why doesn't python threads show an associated PID?  On spawning python
| > threads using the threading module I can only see the main thread's pid on
| > using top or ps unix command, no  subprocesses are displayed. In otherwords
| > top or ps in not aware of any subprocesses created using threading module in
| > python.
| >
| > Whereas in Java , creating threads will result in separate pid , these
| > subprocesses can be listed using top or ps. Java threads get mapped to the
| > cores in the system.
| 
| I think you're confused about what threads and subprocesses are. They
| are completely different mechanisms for concurrent code. Threads never
| show up on top or ps, in any language ... or the language isn't offering
| threads. I don't know Java, so I can't really comment on it much, but it
| may be misusing the 'thread' word, but I somehow doubt it. I suspect
| you're just mistaken about what Java is offering.

No, you're mistaken about the threading models on offer.

Some systems offer a threading model where threads can have distinct
process ids; the only real criterion is that they share the same address
space.

The advantages of separate process ids for threads include letting
the OS arrange their scheduling, delivery of signals (on UNIX systems)
to a particular thread, ability to use multiple cores. On the flipside,
threads with distinct process ids tend to be more expensive to set up
and may be more expensive in thread switching.

Java has long shipped with multiple threading implementations; IIRC
"green threads" is an "all in one process id" model that can be used on
any platform.

Some use a mix of heavyweight (threads with distinct pids) and
lightweight threads.

| But, in Python, only one thread actually ever executes actual Python
| code at any given time.

In CPython this is true. Other implementations like Jython can use
other threading models; I'd expect Jython to take a lot of advantage of
Java's native threads.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Seeing my great fault
Through darkening blue windows
I begin again
- Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web