Tip for Pyglet-Developer

Moderator: Moderator

Posts: 64
Joined: Sat Dec 06, 2008 2:19 pm

Tip for Pyglet-Developer

Postby LivingOn » Sat Mar 14, 2009 4:06 pm

After the termination of a Pyglet, the sys.path is not reset and modules remain in the environment Pyglet loaded. This can cause problems with other Pyglets.
To work around this problem, you can reset sys.path and remove loaded modules at the end of pyglet execution.

Here is one example of my pyglet cc2tv:

Code: Select all

import os
import sys

if __name__ == "__main__":

    # save module-environment
    sysmodules = sys.modules.keys()

    # expand path to find own modules
    sys.path.append("%s/lib" % os.getcwd())

    # load window and start execution
    from CC2TV import CC2TV
    win = CC2TV()
    del win

    # restore sys.path

    # remove all subsequently loaded modules
    def remove_module(name): del sys.modules[name]
    [ remove_module(name) for name in sys.modules.keys()
                                if name not in sysmodules ]

Posts: 2
Joined: Mon Jun 22, 2009 2:06 am

Re: Tip for Pyglet-Developer

Postby ammser » Mon Jun 22, 2009 2:12 am

Great tips, very cool, Thanks.

User avatar
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany

Re: Tip for Pyglet-Developer

Postby Uatschitchun » Mon Feb 08, 2010 8:07 pm

Pls, all pyglet-devels, could you pls check, if you use this!!

We have a problem with some pyglets making others not work anymore ;(

Does this also work if a pyglet crashes?

P.S. I made this topic "global" for a while, for to make it known ;)

Return to “announcements”

Who is online

Users browsing this forum: No registered users and 1 guest