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

[pygame] Re: pygame and file object compatibility; slow.



After fussing with it for a few hours it seems to be a problem with
either pygame or the tar file objects. The time it takes to extract
the file into memory is around 0.003s or so. The problem occurs
exactly when it hits the pygame.image.load. I eventually found a
method to load them faster (8s as opposed to 9 hours for 379 images.)
Still a bit long.  Anywho, I did move onto ZIP and whala, problems are
gone. Now it only takes 0.07s to load all 379 images. Thanks for the
response though. I think I'll just stick with ZIP for now.

On Mar 28, 3:42 am, Luke Paireepinart <rabidpoob...@xxxxxxxxx> wrote:
> On Sat, Mar 27, 2010 at 11:11 PM, Maize <vhxonl...@xxxxxxxxx> wrote:
> > Currently I am working on a game project in pygame. We have a library
> > folder containing all of our images, text files, and fonts. We are
> > converting this to an archive file because we have many many files
> > (~12,000) and don't want to litter folders and files everywhere on a
> > users computer. We turned to the tarfile module simply because it was
> > built in and easy to use. Currently, I am using tarfile's extractfile
> > to retrieve a file object from the tar file and put it into memory.
> > Pygame does not like tarfile's file objects at all.
>
> > Using pygame.image.load, if I pass the filename and directory, the
> > load time is near instant at 0.0 ~ 0.0009s. Whereas passing the file
> > object created by tarfile increases the load time to an insane 1.4 -
> > 1.5s! Even worse: passing a file object to pygame.font.Font produces a
> > segmentation fault. Am I missing something or is there an issue with
> > tar file objects?
>
> in Python a "file" object is just an object that contains some specific
> methods, read, write, etc.  It's not specified how the library actually
> implements them.
> It sounds like your files aren't being extracted until load time.  Perhaps
> you can pre-extract the files you need into memory before loading?  That
> would most likely fix your issue.
>
> Also there is a zip library built into Python, isn't there?  Why use tar?
> tar files aren't even compressed, are they?
>
>
>
> > I have a feeling this will be consistent with many different file
> > objects. Any help is greatly appreciated and welcomed.
>
> Um, no, this is specific to their implementation of file objects.  That's
> the side-effect of duck-typing, you have to depend on libraries implementing
> their interfaces correctly.
> Sounds like something's wrong with the tar library, or you're not using it
> in the intended manner.
>
> I'd personally look into using another library and extracting to memory at
> runtime, unless you are running on a platform with severe memory
> constraints?
>
> -Luke