[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] More optimisation questions



On Fri, 2005-12-16 at 15:28 +0900, Guillaume Proux wrote:
> I am also worried that i might be a casualty of the GIL. If separate
> thread takes hold of the CPU for too long, (even if really 4 lines of
> python) could I hit the problem that my main thread gets to wait a bit
> too long to get the GIL?

Generally, OpenGL can only safely be called from the primary thread.
This may not always be the case, but it is a good rule when dealing with
hardware accelerated graphics.

This may be a problem. Call "sys.setcheckinterval(20)" as your program
insitializes. This will increase the general overhead of running python
threads, but the GIL will switch contexts more frequently, which could
be stalling out your primary thread.

Also be aware that when Pygame loads image (and other processes that may
take awhile) it ensures that the GIL is released. Allowing other python
threads to run while that thread waits on disk io or C image processing.

I notice the "tostring" function doesn't drop the GIL while processing,
but that's probably ok. 

If your images are very large (full screen? 1280x1024?) You may consider
tiling the image into 4 textures. Then you could create the textures in
smaller chunks. You'll need to make sure the four quads you render are
aligned, but I don't think that is too hard. (Actually, if you are
bilinear filtering you will have to be clever around the borders)