Get thread pid

ma mabdelkader at gmail.com
Fri Jan 30 17:53:46 CET 2009


I think issue here is that you're invoking a system call (using either the
subprocess module or os.popen*) from your threads. Those *are* external
processes and will show up under pstree since they have a parent process. If
you're using subprocess.Popen() the object that is returned has an attribute
'pid' that can be accessed (which would serve your purpose).

Please note that *this is NOT a thread id*


On Fri, Jan 30, 2009 at 11:33 AM, Alejandro
<alejandro.weinstein at gmail.com>wrote:

> On Jan 30, 9:11 am, Jean-Paul Calderone <exar... at divmod.com> wrote:
> > [clarification about threads]
>
> Thank you for the clarification. I will reformulate my question:
>
> pstree and also ntop (but not top) show a number for each thread, like
> for instance:
>
> $pstree -p 9197
> python(9197)€ˆ€{python}(9555)
>              †€{python}(9556)
>             †€{python}(9557)
>             †€{python}(9558)
>             †€{python}(9559)
>             †€{python}(9560)
>             †€{python}(9561)
>             †€{python}(9562)
>             †€{python}(9563)
>              „€{python}(9564)
>
> Is is possible to get the number corresponding to each thread?
>
> The reason I am interested is because one of my thread is hogging the
> CPU, and want to find which one is the culprit.
>
> Regards,
> Alejandro.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090130/712c5e44/attachment.html>


More information about the Python-list mailing list