View Single Post
epage's Avatar
Posts: 1,684 | Thanked: 1,562 times | Joined on Jun 2008 @ Austin, TX
#21
Originally Posted by Khertan View Post
An other things to doesn't freeze the ui and to not slow down the device by using intensive thread is to divide tasks in very small tasks and to use a sigleton with gidle :

import gobject

class _DeferClass(object):
_calls=[]
_ref=None
def __new__(cls,*args,**kw):
if cls._ref is None:
cls._ref = super(_DeferClass,cls).__new__(cls,*args,
**kw)
return cls._ref

def __len__(self):
return len(self._calls)

def __call__(self,func,*args):
def NextCall():
(func,args)=self._calls[0]
func(*args)
self._calls=self._calls[1:]
return self._calls!=[]
if not self._calls: gobject.idle_add(NextCall)
self._calls.append((func,args))

I ve many example to give and there is so man things to say that i ll be able to write a book about py opimization.

So if you need so help optimizing code i can maybe help you.
An alternative is to use a worker thread per set of logic data to avoid locks and then wrap it in classes to handle the jumping between the main loop and my thread.

AsyncLinearExecutor code:
https://garage.maemo.org/plugins/ggi...51e98721401e72

Code that uses AsyncLinearExecutor:
https://garage.maemo.org/plugins/ggi...51e98721401e72
__________________
770, n810, n900, Ideapad S10-3t
TheOneRing, DialCentral, Gonvert, Quicknote, Multilist, ejpi, nQa, Waters of Shiloah
Programming Blog
 

The Following User Says Thank You to epage For This Useful Post: