[Stackless] Santa concurrency problem

Carlos Eduardo de Paula carlosedp at gmail.com
Mon Mar 26 22:26:42 CEST 2007

Great Richard, I have seen this solution before in some code you
wrote, I just didnt remembered when replying here...

Gonna substitute with the new ManageSleepingTasklets 2.0 :D on
examples we have in the examples project.


On 3/26/07, Richard Tew <richard.m.tew at gmail.com> wrote:
> On 3/26/07, Carlos Eduardo de Paula <carlosedp at gmail.com> wrote:
> > What is taking a hit on CPU is the ManageSleepingTasklets tasklet, it
> > gets that usage in its loop.
> >
> > What I can do for throttling the cpu usage is put a time.sleep(0.001)
> > inside the while loop, with it we can have a decent precision on time
> > (1 milisecond) and having the CPU at low usage...
> >
> > Maybe Richard can help us out about a cleaner solution on this...
> The Sleep code here is copied from the simple example I wrote.
> Unfortunately like most low level Stackless examples it only
> really serves to demonstrate what you can do, now how you should
> do it in all cases.  In the case here, since it is responsible for
> awakening tasklets and if it knows none are waking anytime
> soon, it is safe to avoid a busy wait by adapting the code to
> use time.sleep for the interim.
>   def ManageSleepingTasklets(self):
>     while True:
>       if len(self.sleepingTasklets):
>         endTime = self.sleepingTasklets[0][0]
>         if endTime <= time.time():
>           channel = self.sleepingTasklets[0][1]
>           del self.sleepingTasklets[0]
>           # We have to send something, but it doesn't matter what as
> it is not used.
>           channel.send(None)
>         elif stackless.runcount == 1:
>           # We are the only tasklet running, the rest are blocked on
> channels sleeping.
>           # We can call time.sleep until the first awakens to avoid a busy wait.
>           delay = endTime - time.time()
>           print "wait delay", delay
>           time.sleep(delay)
>       stackless.schedule()
> Cheers,
> Richard.

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list