pyglet.app.run() freezes python

482 views
Skip to first unread message

Pranav Ravichandran

unread,
Dec 24, 2010, 4:48:15 AM12/24/10
to pyglet-users
I was looking at playing sounds using python and stumbled upon pyglet.



import pyglet

foo=pyglet.media.load('abc.mp3')
foo.play()

pyglet.app.run()



The mp3 file is in the same folder as the .py file. When I run it, it
plays the mp3 file, but python freezes up. I noticed that the same
thing happens when I type pyglet.app.run() in interactive mode.

I'm a python newbie, just got started with it.

Any help would be much appreciated.

George Oliver

unread,
Dec 25, 2010, 1:59:52 PM12/25/10
to pyglet...@googlegroups.com
On 12/24/2010 1:48 AM, Pranav Ravichandran wrote:
>
> The mp3 file is in the same folder as the .py file. When I run it, it
> plays the mp3 file, but python freezes up. I noticed that the same
> thing happens when I type pyglet.app.run() in interactive mode.
>


I'm not exactly sure if this is what the problem is, but Python will
'freeze' until it returns from a process (running the pyglet app), it's
normal behavior.

That said, you -can- affect the running app by modifying its source and
reloading the affected part (ignoring some details there), but as far as
I know most people don't develop with Python that way.

Steve

unread,
Dec 25, 2010, 4:16:02 PM12/25/10
to pyglet-users
All right, I was going to wait until someone more knowledgeable
responded, but the first response is a misunderstanding of the
question.

The poster is wondering why, when he types pyglet.app.run() in the
REPL, he is unable to continue typing commands (e.g. live coding
pyglet).

This is because the pyglet event loop (what's inside pyglet.app.run())
executes on the _main thread_. It looks something like this:
while True:
get event
process event
if user wants to exit, return

If you want to write pyglet code live in the REPL, you'll probably
have to do what this guy did:
http://kooneiform.wordpress.com/2010/01/05/pyglet-and-livecoding-1/

If you're a newbie, I really don't recommend messing with that until
you understand more of what's going on. Just work with source files,
which are more predictable.

Anonymouse

unread,
Dec 25, 2010, 5:34:36 AM12/25/10
to pyglet-users
This is normal - pyglet.app.run() runs the main loop and doesn't
return (end) until the program finishes running. If you have a window,
it should end as soon as you close that window.

Good luck!

Pedro Arana

unread,
Dec 25, 2010, 7:41:29 PM12/25/10
to pyglet...@googlegroups.com
On Fri, Dec 24, 2010 at 03:48, Pranav Ravichandran <prp....@gmail.com> wrote:

> I was looking at playing sounds using python and stumbled upon pyglet.

Maybe this is the problem, wrong tool for the task?

Greetings


--
Defiende tu derecho a pensar, porque incluso pensar de manera errónea
es mejor que no pensar.
-Hipatia de Alejandría

Hugoagogo

unread,
Feb 21, 2011, 2:22:12 AM2/21/11
to pyglet-users
Sorry for a bit of a bump but, i am having similar issues, i
understand that idle should freeze untill the pyglet closes but pyglet
itself shouldn't freeze up on a run should it?
Reply all
Reply to author
Forward
0 new messages