Threads in embedded interpreter doesn't run

Discussion in 'Python' started by devrim.erdem@gmail.com, Oct 19, 2004.

  1. Guest

    Hello,

    I am trying to implement threads in my embedded interpreter.

    The host application is a C++ app which has a built-in python
    interpreter. After initialization of the app just before it starts an
    endless while loop ( which does OpenGL rendering ) the thread is
    created and started. Like this :

    class TmpThread( threading.Thread ):
    def __init__( self ):
    threading.Thread.__init__( self )
    print "%s is constructed." % self
    def run(self):
    while( 1 ):
    print "this is tmpthread"
    time.sleep( 1 )

    tmp = TmpThread()
    tmp.start()

    The problem is that the thread prints its message a couple of times
    and then stops. During the main loop of my program, the python thread
    doesn't run. After termination of the loop, the thread starts printing
    the message.

    Could anyone give me some hints to understand why the thread can not
    execute during my application loop.

    Thanks in advance,
    Devrim.
     
    , Oct 19, 2004
    #1
    1. Advertising

  2. Jeff Shannon Guest

    wrote:

    >Could anyone give me some hints to understand why the thread can not
    >execute during my application loop.
    >
    >


    This is a complete shot in the dark, but is there any chance that your
    rendering loop is holding on to the Python GIL? Doing so would prevent
    any (other) Python code from running for as long as the lock is held.

    Jeff Shannon
    Technician/Programmer
    Credit International
     
    Jeff Shannon, Oct 20, 2004
    #2
    1. Advertising

  3. Guest

    Jeff Shannon <> wrote in message news:<>...
    > wrote:
    >
    > >Could anyone give me some hints to understand why the thread can not
    > >execute during my application loop.
    > >
    > >

    >
    > This is a complete shot in the dark, but is there any chance that your
    > rendering loop is holding on to the Python GIL? Doing so would prevent
    > any (other) Python code from running for as long as the lock is held.


    Thanks Jeff.

    I haven't so far explicitly done anything with Python GIL in my
    application. Is there a function which could tell me if the Python GIL
    is held or not ?
     
    , Oct 20, 2004
    #3
  4. Jeff Shannon Guest

    wrote:

    >Jeff Shannon <> wrote in message news:<>...
    >
    >
    >> wrote:
    >>
    >>
    >>
    >>>Could anyone give me some hints to understand why the thread can not
    >>>execute during my application loop.
    >>>
    >>>
    >>>

    >>This is a complete shot in the dark, but is there any chance that your
    >>rendering loop is holding on to the Python GIL? Doing so would prevent
    >>any (other) Python code from running for as long as the lock is held.
    >>
    >>

    >
    >Thanks Jeff.
    >
    >I haven't so far explicitly done anything with Python GIL in my
    >application. Is there a function which could tell me if the Python GIL
    >is held or not ?
    >
    >


    I've never done any extending/embedding, so I don't really know; I'm
    just working with what I've seen mentioned here on c.l.py (and I usually
    skip extending/embedding threads, since I don't do it). But I believe
    that the GIL is released and reclaimed by (from vague memory)
    PyBeginAllowThreads and PyEndAllowThreads, or something like that.
    You'll need to read through the extending/embedding docs to figure out
    how they work, though, because I don't know enough to help you there.
    :) Just remember that you can't touch any Python internals (or do much
    of anything through the interpreter) unless you hold the GIL, and that
    no other Python threads can run while you hold it.

    Jeff Shannon
    Technician/Programmer
    Credit International
     
    Jeff Shannon, Oct 21, 2004
    #4
    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. Tim Stanka
    Replies:
    0
    Views:
    325
    Tim Stanka
    Jul 19, 2004
  2. Charlie DeTar

    embedded python and interpreter threads

    Charlie DeTar, Dec 7, 2004, in forum: Python
    Replies:
    2
    Views:
    696
    Charlie DeTar
    Dec 7, 2004
  3. Peter Newman
    Replies:
    1
    Views:
    457
  4. Replies:
    4
    Views:
    611
  5. Replies:
    3
    Views:
    788
    Ziga Seilnacht
    Jan 3, 2007
Loading...

Share This Page