come back on that
>    try:
>        msg = my_queue.get(False)
>    except Queue.Empty:
>        return
>    # process message
I was wrong.
As you put it in the schedule function, it will not take that much
CPU, of course.

Maybe, instead of using a queue, in your sample, I will use a simple
dict with a lock.
I have many Consumers (view) for the same variable.
If one view get the message out of the queue, the other one will not
get it.

On 12 fév, 12:13, Philippe <[email protected]> wrote:
> >    try:
> >        msg = my_queue.get(False)
> >    except Queue.Empty:
> >        return
> >    # process message
>
> I think that this spends a lot of CPU checking the queue (for nothing
> most of the time)
>
> something like this, will wait, using no CPU, most of the time
> and sometimes, will get something out of the queue and process it.
>
> >  t = threading.Thread(target=check)
> >  def check():
> >      running = True
> >      while running:
> >          msg = my_queue.get()
> >          if msg == 'stop':
> >              runnning = False
> >          else:
> >              process_msg(msg)
>
> but, it's in a thread :/
>
> I am not a specialist, so maybe, this is not correct !
> but it's what I think...
>
> Thank you for your explanation of pyglet FPS. It's clear to me now.
> Still, I do not find how to emit a event that will redraw my window,
> or part of it.
> Your code with use of schedule() is the best solution so far.
>
> I feel sad to not be able to simply refresh the objects that need to,
> based on an event (instead of checking periodically).
> I will search little but more !
>
> On 11 fév, 20:31, claudio canepa <[email protected]> wrote:
>
>
>
>
>
>
>
> > On Sat, Feb 11, 2012 at 12:12 PM, Philippe <[email protected]> wrote:
> > > nice help ! thank you.
>
> > > about the queue, personally, I use the thread safe Queue.Queue()
> > >http://docs.python.org/library/queue.html#module-Queue
>
> > > then, something like that
> > > while running:
> > >    msg = my_queue.get(True, 0.1)
>
> > > no need of threading.Lock() like that.
>
> > > I checked the schedule function you used in the GameCtrl (line 65).
> > > from the doc "Schedule a function to be called every frame"
> > > What does it mean "every frame" ?
> > > Is there a fix framerate in cocos2D ?
>
> > While starting the window  with director.init(...) you can pass a kw-param
> > vsync = True / False
> > Default is True, which means pyglet will try to synchronize with the
> > vertical retrace.
> > But, if your code don't have any schedule() call, it will try to spare
> > battery and cpu / gpu , thus calling about 10 times per second.
>
> > You can see the actual fps with
> > director.show_FPS = True
>
> > > I will try to do like above (in a thread):
>
> >  while running:
>
> >    msg = my_queue.get(True, 0.1)
>
> > > meaning that it waits all the time, and sometime get something from
> > > the queue.
> > > the 0.1 means that it will not wait for ever anyway. then, if
> > > runnning==false, the thread will exit (simple way to close the
> > > application).
>
> > Why not get with
> >     try:
> >         msg = my_queue.get(False)
> >     except Queue.Empty:
> >         return
> >     # process message
>
> > This way you don't spend time waiting in an empty queue
>
> > > I think that with you 2nd sample, I can do what I need.
> > > thanks a lot !
>
> > Glad
>
> >  No doubt you will find some interesting things with threading + pyglet,
> > consider to take notes and blog / post somewhere your findings
>
> > --
> > 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.

Reply via email to