An update - I was able to find a solution to the hang that was happening
when I would try closing my pyglet application. I replaced subprocess.call
with subprocess.popen, which seems better, but this wasn't what was
actually causing the problem. It was the timer I was using from the
threading module. It looks like the timer was never being stopped on close,
and that was affecting how pyglet was closing. So i added 't.cancel' on
closing events to fix it. Here is the updated code:
pyglet.options['audio'] = ('openal', 'silent')
window = pyglet.window.Window()
be = ['is', 'was', 'will be', 'is not']
song2 = pyglet.media.load('beats/knock.mp3', streaming=False)
song12 = pyglet.media.load('beats/drop-2.mp3', streaming=False)
player = pyglet.media.Player()
def beatz():
playlist = [song2, song12]
shuffle(playlist)
player.queue(playlist[0])
player.queue(playlist[1])
player.play()
def on_player_eos():
print('repeating')
beatz()
player.push_handlers(on_player_eos)
#### WORDS STUFF #####
barLen = list(range(1,10))
timez = [.5, .75, 1.0, 1.5, 2.0]
def rap():
t = Timer(random.choice(timez), rap)
@window.event
def on_key_press(symbol, modifiers):
if symbol == key.A:
r.terminate()
t.cancel()
print('exiting')
pyglet.app.exit()
@window.event
def on_close():
r.terminate()
t.cancel()
print('exiting')
pyglet.app.exit()
bar = ' '.join(random.choice(be) for _ in range(random.choice(barLen)))
r = subprocess.Popen('say ' + bar, shell=True)
r.wait()
sys.stdout.flush()
t.start()
def freestyle():
beatz()
t = Timer(1.5, rap)
t.start()
if __name__ == "__main__":
freestyle()
pyglet.app.run()
This works great. Thanks so much for all your help!
On Sat, Jun 25, 2016 at 9:59 AM Mitchell Barton <
[email protected]> wrote:
> So I just tried using subprocess.run, and subprocess.popen to run the
> commands, but they still werent working. Maybe I'm missing something else
> that is causing me trouble. I will keep trying though
>
> On Sat, Jun 25, 2016 at 9:18 PM Elliot Hallmark <[email protected]>
> wrote:
>
>> Subprocess.popen is non blocking, fyi.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "pyglet-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/pyglet-users/uxgMsN-i6Ro/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/pyglet-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.