Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Threads in embedded interpreter doesn't run (http://www.velocityreviews.com/forums/t337206-threads-in-embedded-interpreter-doesnt-run.html)

devrim.erdem@gmail.com 10-19-2004 08:55 PM

Threads in embedded interpreter doesn't run
 
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.

Jeff Shannon 10-20-2004 12:51 AM

Re: Threads in embedded interpreter doesn't run
 
devrim.erdem@gmail.com 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


devrim.erdem@gmail.com 10-20-2004 02:21 PM

Re: Threads in embedded interpreter doesn't run
 
Jeff Shannon <jeff@ccvcorp.com> wrote in message news:<10nbdfqhgkgra70@corp.supernews.com>...
> devrim.erdem@gmail.com 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 ?

Jeff Shannon 10-21-2004 07:27 PM

Re: Threads in embedded interpreter doesn't run
 
devrim.erdem@gmail.com wrote:

>Jeff Shannon <jeff@ccvcorp.com> wrote in message news:<10nbdfqhgkgra70@corp.supernews.com>...
>
>
>>devrim.erdem@gmail.com 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



All times are GMT. The time now is 05:21 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.