Tip for Pyglet-Developer

Moderator: Moderator

LivingOn
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()
    win.doModal()
    del win

    # restore sys.path
    sys.path.pop()

    # 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 ]
:wink:

ammser
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
Uatschitchun
Overlord
Posts: 3189
Joined: Tue Dec 06, 2005 6:55 pm
Location: Germany
Contact:

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 ;)
Lg
Roman


Return to “announcements”

Who is online

Users browsing this forum: No registered users and 1 guest