Current execution frame of another thread?

Discussion in 'Python' started by skip@pobox.com, Nov 17, 2005.

  1. Guest

    I would like to try a sampling approach to profiling. My thought is to have
    a profiling thread that samples the execution frame of all the other
    started threads. I don't see any path from the threads returned by
    threading.enumerate() to their current frames. Am I missing something?

    Thx,

    Skip
     
    , Nov 17, 2005
    #1
    1. Advertising

  2. wrote:
    > I would like to try a sampling approach to profiling. My thought is to have
    > a profiling thread that samples the execution frame of all the other
    > started threads. I don't see any path from the threads returned by
    > threading.enumerate() to their current frames. Am I missing something?


    I doubt that works. As python uses the OS underlying threading model, it
    doesnn't know about the internal management structures - and even it
    knew, these had to be carefully designed for that exact purposes of
    yours, as the stack frame can only be safely inspected by the thread
    _running_ in it.

    An external thread could be interrupted at all times while traversing
    other threads management structures, and then find a corrupted memory
    location when it is re-scheduled.

    Maybe one could write a threading model that allwos for hooks in the
    scheduler (which has all the time in the world for such stuff) - but I'm
    not aware that that's possible under e.g. pthreads, so there is unlikely
    a python-way to do so.

    Regards,

    Diez
     
    Diez B. Roggisch, Nov 17, 2005
    #2
    1. Advertising

  3. wrote:
    > I would like to try a sampling approach to profiling. My thought is to have
    > a profiling thread that samples the execution frame of all the other
    > started threads. I don't see any path from the threads returned by
    > threading.enumerate() to their current frames. Am I missing something?



    Just another thought: Maybe stackless python can be of use here - as it
    epxlicits the stack frame, you might be able to inspect it. But I
    _think_ basically the same limitations apply as in my other post - you'd
    need to be able to stop a thread, scan its frame, and reschedule it.

    Diez
     
    Diez B. Roggisch, Nov 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manu
    Replies:
    1
    Views:
    6,106
    Natty Gur
    Jul 20, 2003
  2. Søren M. Olesen
    Replies:
    0
    Views:
    581
    Søren M. Olesen
    Nov 13, 2003
  3. Microsoft
    Replies:
    3
    Views:
    700
    Hugo Wetterberg
    Oct 4, 2004
  4. sayoyo
    Replies:
    3
    Views:
    1,160
    sayoyo
    Feb 16, 2004
  5. Replies:
    3
    Views:
    180
Loading...

Share This Page