[Stackless] Mistakes, Corrections and Questions Re: Stackless Digest, Vol 28, Issue 8

Richard richard at ccpgames.com
Wed May 10 12:36:27 CEST 2006


> From: Richard Tew [mailto:richard.m.tew at gmail.com]
> 
> For what you want, you need extra support added to
> Stackless which lets tasklets be added and removed
> from the channel queue, in the same manner as
> insert and remove work on the scheduler.

But you could always use __setstate__ and __reduce__ :)

import stackless, pickle
c = stackless.channel()

def f(n):
	print 'enter', n
	ret = c.receive()
	print 'exit', n, ret


l = [ stackless.tasklet(f)(i) for i in range(4) ]
for x in l:
	x.run()

x, y, (balance, flags, tasklets) = c.__reduce__()
t = tasklets[0]
del tasklets[0]
c.__setstate__((balance, flags, tasklets))

while c.balance:
	c.send("die")

s = pickle.dumps(t)
t = pickle.loads(s)

x, y, (balance, flags, tasklets) = c.__reduce__()
tasklets.append(t)
c.__setstate__((balance, flags, tasklets))

while c.balance:
	c.send("die")

I also tried mixing in a tasklet which had blocked on a
schedule call, but that resulted in a crash, which isn't
that surprising.  As long as you stick to tasklets which
blocked on channels, you should be OK.

Richard.

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list