[Stackless] cPickle should work?
Andrew Francis
andrewfr_ice at yahoo.com
Tue May 2 20:30:31 CEST 2006
Hello colleagues:
When I run the following programme with dump(), it
crashes with an RuntimeError exception at the end of
the problem. When I use dumps(), things are fine. I am
using Stackless binary 2.4.3 Dlls. I have included the
programme.
Cheers,
Andrew
in task A
in task C
C about to sleep
in task B
B about to sleep
A about to sleep
pickling tasks
unpickling tasks
A woke up
C woke up Hello
B woke up Hello
[RuntimeError occurs and Python crashes]
!/usr/bin/env python
import stackless
import cPickle as pickle
import sys
"""
Serialisation test
April 27th, 2006
Andrew Francis
See if I can use channels along with pickling.
Don't understand why I get a crash
"""
running = []
class Foo(object):
x = 10
y = 20
class Task(Foo):
def __init__(self, name, channel):
self.name = name
self.channel = channel
def execute(self):
print "in task ", self.name
print self.name, " about to sleep"
message = self.channel.receive()
print self.name, " woke up", message
class P(Foo):
def __init__(self, name, list, channel):
self.name = name
self.tasks = list
self.running = []
self.channel = channel
def execute(self):
print "in task ", self.name
for task in self.tasks:
t = stackless.tasklet(task.execute)()
running.append(t)
t.run()
print self.name, " about to sleep"
message = self.channel.receive()
print self.name, " woke up"
c = []
for i in range(0,3):
c.append(stackless.channel())
p = P("A", [Task("C",c[1]),Task("B",c[2])], c[0])
t = stackless.tasklet(p.execute)()
running.append(t)
t.run()
try:
print "pickling tasks"
#schedule()
f = open("test1.dat","w")
pickledTasks = pickle.dump(running,f)
f.close()
print "unpickling tasks"
f = open("test1.dat")
pickle.load(f)
f.close()
for channel in c:
channel.send("Hello")
while stackless.getruncount() > 1:
stackless.schedule()
except:
print sys.exc_info()
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list