[Sugar-devel] pygame activities stop XO sleep?
quozl at laptop.org
Thu Dec 30 19:30:55 EST 2010
On Fri, Dec 31, 2010 at 07:40:55AM +1000, Peter Hewitt wrote:
> It seems that my pygame activities prevent the XO (both models) from
> going to sleep. This problem persists even after my activity has
I've reviewed your code, profiled it, and made adjustments. It is
indeed your code causing the laptop not to go to sleep.
> Someone suggested that this happens with other pygame activities.
Yes, it is a common mistake to make when using sugargame and pygame. It
is mainly caused by allowing blitting and display flip to occur without
any need for it. Some pygame applications require continual update, but
Boxes does not need to update the display until the learner responds,
yet it calls flip up to 40 times a second.
See the attached profiling graph. This was prepared from only a few
seconds of running, but it shows that pygame's flip() and and your
display() were called 274 times, resulting in 5080 rectangles being
drawn, and 727 surface blits. I'm happy to explain how I prepared this,
since others here explained it to me.
> Does anyone have a solution for this problem?
In the attached patch I've modified your code as follows:
1. avoided the costly screen update unless there were mouse events, by
using a redraw counter that allows redraws until the counter is
depleted, ... this shows significant CPU reduction a couple of seconds
after the events cease, ... it's a bit of a hack, but I didn't have time
to figure out from your game engine how to detect idle state, ... the
initial value of the counter may need to be increased if the logic is
not changed, it might cause long wizard responses to be delayed until
the mouse is moved.
2. added escape and Control/Q handlers temporarily for profiling without
activation from Sugar, (probably no need for these in the final
3. added profiling (do not use this in the final version),
With these changes an XO-1.5 goes into idle suspend after starting the
activity in Sugar and waiting for a while.
(By the way, I couldn't find a copyright or license in the code. That
makes any contribution ambiguous. Please add a copyright and license so
that contributions are welcomed.)
> It doesn't happen with my Mirabelle SoaS.
Mirabelle does not have idle suspend, which is why it doesn't happen
there. You may have seen a screen blanking though. That's a different
On Fri, Dec 31, 2010 at 09:57:16AM +1000, Peter Hewitt wrote:
> 2. How does this newbie monitor CPU usage on the XO?)
At another prompt, such as a shell prompt accessed over the network,
top -d 1
and while watching that, run the activity. I use SSH over wireless for
that, so that the full cost of graphics updates are seen in the top
output. Using top in a Terminal might give you bogus advice.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 101609 bytes
Desc: not available
More information about the Sugar-devel