[Stackless] Watchdog, EVE like beNice implementation and how tasklet.capture() works

Richard richard at ccpgames.com
Fri Mar 24 14:47:04 CET 2006

> From: Juho Mäkinen
> This is what I have come so far. I'm haven't quite figured out
> what tasklet.capture() does. It looks like it's some kind of fork()
> function. Could somebody describe in detail what it does?
> Anyway, this is the only way I have managed to implement this
> kind of functionality. The problem is, that it's quite slow.

Capture and become are depreciated.  Channels are a simpler
way to do a lot of things :)  I can't even remember what we
used to use capture and become for, it has been so long
since we purged them from our codebase.

I ran your script in a console and it took 141 seconds.

The following included script I wrote took 3 seconds.

I imagine that any non-capture based version would
take a similar length of time.

-- snip here --

# start of beNice test
import stackless
from time import time
from stackless import channel,tasklet

nicedChannel = stackless.channel()
# We do not want sends to actually schedule the awoken
# tasklets (the default channel behaviour).
nicedChannel.preference = 0

def taskletTest(n):
 print "tasklet " + n + " started"
 c = 0
 for i in xrange(1000):
   c = c + 1
 print "tasklet " + n + " done with c == " + str(c)

def beNice(n):
 global nicedChannel

print "Creating 1000 tasklets, which each does 1000 beNice operations"
for i in xrange(1000):
 stackless.tasklet(taskletTest)("tasklet #" + str(i))

start = time()
for i in xrange(1001):
 # Put the beNice'd tasklets back into running queue
 # so that the watchdog can run them
 while nicedChannel.balance < 0:
  # Our channel is configured to return to this tasklet and to just
  # schedule the awoken one for the run call to deal with.
 while stackless.getruncount() != 1:
   t = stackless.run(100000)
   if t:
     print "Watchdog catch: " + str(t)

end = time()
print "execution time: " + str(end-start) + " second"
# end of beNice test

-- snip here --

But after talking with Kristján, this is not what our
BeNice does.  Apparently where my guess just reschedules the
tasklets, what our code does is mark the channel balance
and just send that many times (if we looped on the balance
like I do, we'd be continually sending to tasklets that were
looping on BeNice calls).


Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list