a quick and dirty workaround ... http://pastebin.com/8ZpyEZ6U
use a Lock() to share a list of data from director. use schedule_interval to retrieve datas. it's really sad to update the datas through a schedule_interval but works.. I hope I can find a way to use events later ! On 10 fév, 08:27, Philippe <[email protected]> wrote: > I could probably pass datas from my thread to my Sprite using a Queue. > But actually, that thread owns the datas for all my layers and > sprites. > And the datas are updated by a distant application (UDP).. > I do not think that the queue could be shared between all my > cocosnodes. > > I saw the pyglet user-group. it deals a lot on how to embed pyglet in > a thread. > Actually, maybe what I need is to embed my thread into pyglet. > > If I can share a queue between my thread and pyglet main thread, it > will work. > I know how to deal with queue, but I do not know where to do that ? > In the Director ? > I should subclass it ? > > thanks for you help ! > > On Feb 9, 11:22 pm, claudio canepa <[email protected]> wrote: > > > > > > > > > On Thu, Feb 9, 2012 at 6:20 PM, Philippe <[email protected]> wrote: > > > Hello, > > > > In my threading.Thread(target=self.timed_event)... > > > I simplified timed_event to get a small sample that reproduce my > > > problem. > > > > But actually, inside timed_event, I have a UDP communication with some > > > other software. > > > That's why I need that thread. It's a simple communication that > > > include a python Queue(). > > > In that thread, when there is something in the Queue, it will be > > > pushed as a pyglet event for the Layers. > > > > That's the idea ! It works fine in other python software I made. > > > In cocos, I do not know how to remove that thread. Is there some sort > > > of "pyglet thread" available for that purpose ? > > > > My real timed_event function is more like: > > > while self.running: > > > msg = self.my_queue.get() > > > self.dispatch_event('on_data_update_from_thread', msg) > > > If your > > self.dispatch_event('...') > > is in the main thread that would look a lot better than in the sample. > > And, queues from Queue seem to be thread-safe [1] > > > But some comments in the threads [2][3] suggest that maybe the pyglet > > mainloop code should be changed > > > Probably the better would be to rewrite the sample code using a queue, with > > the call to dispatch_event in the main thread, and maybe post at the pyglet > > mail list > > > [1]http://www.ibm.com/developerworks/aix/library/au-threadingpython/ > > [2]http://thread.gmane.org/gmane.comp.python.pyglet.user/3 > > [3]http://thread.gmane.org/gmane.comp.python.pyglet.user/2120 > > > -- > > claudio -- 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.
