Threads in Python

Grant Edwards invalid at invalid.invalid
Fri Sep 2 06:32:48 CEST 2011


On 2011-09-01, Stephen Hansen <me+list/python at 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.

That's because threads are displayed by top/ps in most Linux systems.

>> 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.

If that's on the same system, then those aren't threads.

> 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...

That depends on your threading model.  Some versions of Linux using
LinuxThreads rather than NPTL will show each thread in top or ps.

> or the language isn't offering threads.

The difference between threads and processes isn't whether they show
up in top or ps.  For many years threads showed up in top and ps. They
were still threads.  But, you're right that on most modern,
non-embedded, Linux systems threads don't show up in top or ps.

> 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.

Sure sounds like it.

-- 
Grant



More information about the Python-list mailing list