On Mon, Feb 2, 2009 at 12:35 PM, Lucio Torre <[email protected]> wrote:
>
> also, id like to fix the 'wait almose forever when doing
> pyglet.resources.rescan()' (or something like that) for the next
> release.
>
I have been debugging this issue a bit, and I think I understand the
problem; the short story is that it's not Coco's fault, unluckily :-/
First, a confirmation test: The hang happens as soon as you import
pyglet.resource [1] in an interactive session, if you have a lovely
.pythonrc.py set up in your ~ and PYTHONSTARTUP points to that file.
Try unsetting the PYTHONSTARTUP variable before launching the
interactive session and watch the hang disappear.
The problem is in the way that Pyglet determines its 'base' directory
(check resource.py in Pyglet's code, line 104, get_script_home() ).
This function tries to guess what the directory the main script is
running in, but under these circumstances ends up guessing incorrectly
that your "main script" is your ~/.pythonrc.py, at which point it
goes forward and indexes your whole home directory. Freeze.
This code runs as soon as pyglet.resource is loaded, so you can't even
monkey patch the module to fix the issue; you need to change Pyglet's
code. I changed the get_script_home function to this to fix the hang
(though there's probably a nicer way to detect if you're in an
interactive session):
def get_script_home():
''' docstring... '''
frozen = getattr(sys, 'frozen', None)
if frozen in ('windows_exe', 'console_exe'):
return os.path.dirname(sys.executable)
elif frozen == 'macosx_app':
return os.environ['RESOURCEPATH']
elif hasattr(sys, 'ps1'): # This line was added
return '' # And this line
else:
main = sys.modules['__main__']
if hasattr(main, '__file__'):
return os.path.dirname(main.__file__)
# Probably interactive
return ''
The pyglet site seems to be down at the moment, so I can't submit a
bugreport, but it seems to me that it's up to them to fix it.
Meanwhile, I should think that Cocos should avoid any call to
pyglet.resource.path or pyglet.resource.reindex, at least in it's
__init__.py file. Grepping a bit it seems that some code in
particle.py and draw.py might break due to missing resources if we do
that. Dunno.
Another workaround would be to keep your .pythonrc.py in a folder all by itself.
Cheers,
--
Anthony Lenton
[1] When I say import pyglet.resource I mean do anything that causes
the module to be actually imported, like referring to
pyglet.resource.path. Pyglet's __init__ sets up a lazy loader for the
module.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---