[Stackless] Giving names for tasklets
Juho Mäkinen
juho.makinen at gmail.com
Thu Jun 29 22:39:53 CEST 2006
On 6/28/06, Richard Tew <richard.m.tew at gmail.com> wrote:
> On 6/27/06, Juho Mäkinen <juho.makinen at gmail.com> wrote:
> It would be good to get the smallest possible reproduction case. I
> will try and do that after I finish the port of Stackless to 2.5 if no-one
> has done so already.
I'll check if I can reproduce it again easily and if I run onto it
by misstake, I'll do all I can to create a simple testcase to reproduce it.
> Something I was going to mention about naming tasklets, is how
> we do it a little bit differently at CCP. Maybe it is in the slides from the
> presentation Kristján made at PyCon. We name our tasklets something
> like "Vague Category/Specific Label" and then profile time in the tasklet
> to this hierarchical name.
Nice icea. I was thinking of some type task grouping and that's a nice,
easy and simple way to do it.
Anyway, I ran into more problems, this time with pickling.
Our game (projectxenocide) will use tasklets to script AI (for example).
As they don't contain any traditional states (as the code *is* the state),
the only way to save game state is to pickle those AI scripts (which
are tasklets).
So I started to experiment:
def dumps(uid):
"""
Pickles tasklet with specific uid
"""
global global_tasklets
if (global_tasklets[uid]):
t = global_tasklets[uid]
print "pickling tasklet " + str(t)
s = pickle.dumps(t)
print t
t.kill()
del global_tasklets[uid]
return s
return None
def loads(s):
global global_tasklets
global global_counter
t = pickle.loads(s)
print t
global_counter += 1
t.uid = global_counter
global_tasklets[t.uid] = t
t.insert()
My idea is that I could use dumps() to dump a specified tasklet (associated
with uid, member my previous message with the long code), destroy
the tasklet with kill() and then remove the pickled tasklet as string.
Later I would use loads() to restore the tasklet from death, insert it into
the global_tasklets (with new uid) and insert it back to the runnable queue.
To my first impression, it seems that the tasklet loses it's identity:
>>> a = snake.pyos.dumps(2)
pickling tasklet NamedTasklet("pong", uid: 2)
NamedTasklet("pong", uid: 2)
>>> snake.pyos.loads(a)
<stackless.tasklet object at 0x0918F5B8>
At dumps() the "print t" prints correctly that t is a NamedTasklet,
but at loads() the print t prints that it's a stackless.tasklet object.
Where did the NamedTasklet go?
Another thing is how I should pickle and unpickle a group of tasklets
which communicate together with channels? Is it possible to pickle
just one (for example ping() tasklet from the ping()-pong() example)
tasklet, unpickle it later and except that everything works as expected?
Pickling seems to be a powerfull tool but there's a lot of mysteries
where I'm unable to find answers.
> Thanks,
> Richard
Thanks in advance =)
- Juho Mäkinen
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list