I don't think win.dispatch_events() will work unless it's on the main 
thread, but I haven't look at this code recently.
Is it necessary to create your own event loop? The Player class already 
uses threads internally for playback.

There is an example in the pyglet repositories that might be useful:
https://bitbucket.org/pyglet/pyglet/src/aca0272d8f04e75f345272f8e1b5027ec8091586/examples/synthesizer.py?at=default&fileviewer=file-view-default

If that doesn't help, could you descrbe your project more? 

On Monday, July 3, 2017 at 2:04:04 PM UTC+9, 杨金骉 wrote:
>
> No. I just used loop + dispatch_events() manually.
>
>
> On Jul 3, 2017 1:00 PM, "Benjamin Moran" <[email protected] <javascript:>> 
> wrote:
>
>> Are you using pyglet.app.run() in your code? 
>>
>>
>> On Sunday, July 2, 2017 at 11:29:12 PM UTC+9, 杨金骉 wrote:
>>>
>>> I'm building a real-time sound controller.
>>> I tried to put the sound player and detector of keypress in different 
>>> threads, and used a variable as the messenger. Below is the demo code:
>>>
>>> ## detector
>>> def wait():
>>>     while True:
>>>         win.dispatch_events()
>>>
>>>                      shared.pressing = e['key'] # the got key
>>>
>>>         if shared.figure_released:
>>>             shared.pressing = None
>>>
>>>         time.sleep(0.01)
>>>
>>>
>>> td = threading.Thread(target=wait)
>>> td.start()
>>>
>>> ## player
>>> while 1:
>>>    if shared.pressing=='k':
>>>        # pitch up
>>>    elif shared.pressing=='j':
>>>        # pitch down
>>>
>>> And then I got the error:
>>>
>>>> *RuntimeError: EventLoop.run() must be called from the same thread that 
>>>> imports pyglet.app*
>>>
>>>
>>>
>>> Why can't pyglet get the events from another thread?
>>>
>> -- 
>> 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/PrD2Z8O1qnI/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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.

Reply via email to