Hi, I just tried reproducing this with the current stackless 2.7 and it just 
works.
What stackless are you using
One of the points of stackless is that it can copy/pickle modules just fine.
instead of copy, deepcopy, can you try:

import pickle
print pickle.dumps(t)

and see if this succeeds?


Ø  Probably a lack in my basic understanding of stackless: why is the line  
t.channel = None reached if one of the tasklets is still waiting on a channel?
stackless.run() returns when there are no runnable tasklets.  One tasklet is 
blocked, the other is spent.  So, stackless.run returns.

K



From: [email protected] [mailto:[email protected]] 
On Behalf Of lars van Gemerden
Sent: 2. október 2013 09:47
To: [email protected]
Subject: [Stackless] deepcopying (pickling) channels

Hi all,

I am getting a strange (for me) exception when i try to deepcopy/pickle 
channels that are still sending or receiving, as in:

--------------------------------------------------------------------------------------

import stackless, copy

class Test(object):
    def __init__(self):
        self.channel = stackless.channel()

    def run(self):
        stackless.tasklet(self.sender)()
        stackless.tasklet(self.receiver)()
        stackless.run()

    def sender(self):
        counter = 0
        while counter < 10:
            self.channel.send(counter)
            counter += 1

    def receiver(self):
        counter = 0
        while counter < 12:
            counter = self.channel.receive()
            print counter,
        print "done"

if __name__ == "__main__":

    t = Test()
    t.run()
    t.channel = None
    t = copy.deepcopy(t) #OK

    t = Test()
    t.run()
    t = copy.deepcopy(t) #ERROR

----------------------------------------------------------------------------------------------
the error is:

TypeError: object.__new__(NotImplementedType) is not safe, use 
NotImplementedType.__new__()

somewhere deep into deepcopy, after reading some forums, i think it's trying to 
copy a module.
----------------------------------------------------------------------------------------------

Probably a lack in my basic understanding of stackless: why is the line  
t.channel = None reached if one of the tasklets is still waiting on a channel?

Anyway,in this case the receiver tasklet is still waiting while the sender is 
done, but it also happens if the receiever is done before the sender (e.g. 
change 12 to 8). There is no error if both are done at the same time (change 12 
to 10).

Can someone explain this to me? Is it unavoidable or can it somehow be fixed. 
Otherwise i would probably need to clean up all channels after a stackless run 
is finished and create them before a run starts or do something similar in in 
__getstate__/__setstate__. I use the ??? pattern to allow external interuption 
the stackless run:

----------------------------------------------------------------------------------------------

class OpenTasklets(Tasklets):

    stop = False

    @classmethod
    def run(cls, maxcount = None):
        cls.schedule_channel = stackless.channel()
        cls.schedule_channel.preference = 1
        counter = 0
        while stackless.getruncount() != 1:
            stackless.run()
            cls.reschedule(cls.stop or (maxcount and counter > maxcount))
            counter += 1

    @classmethod
    def schedule(cls):
        if cls.schedule_channel.receive():
            raise TaskletExit

    @classmethod
    def reschedule(cls, stop = False):
        while cls.schedule_channel.balance < 0:
            cls.schedule_channel.send(stop)

    @classmethod
    def tasklet(cls, func):
        return stackless.tasklet(func)
----------------------------------------------------------------------------------------------

Cheers, Lars
--
====================================
Lars van Gemerden
[email protected]<mailto:[email protected]>
+31 6 26 88 55 39
====================================
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless

Reply via email to