Re: Re: trellis.Set.discard

"Sergey Schetinin" <[email protected]>
Newsgroups gmane.comp.python.peak
Message-ID <[email protected]>
After a lot of experimenting, this code seems to provide something useful info:


from pprint import pprint as pp


class CV(Component):
    v = attr(False)
    s = make(Set)

    @maintain
    def maintain(self):
        #print 'in maintain'
        if self.v:
            act = 'add'
            self.s.add(1)
        else:
            act = 'discard'
            self.s.discard(1)
            #task.s.remove(1)
        @on_undo
        def undo(): print "UNDO", act

    @perform
    def perform(self):
        print '-'*20, self.v, self.s



def doit():
    cv = CV()
    print 'undo history:'
    pp(ctrl.undo)
    cv.v = True

print 'TASK'
@atomically
def naked():
    #cell = trellis.Value()
    cell = trellis.Cell(lambda: None)
    ctrl.current_listener = cell
    doit()
    #pp(ctrl.writes)
    ctrl._process_writes(cell)
    ctrl.current_listener = None

print
print 'ATOMICALLY'
atomically(doit)



It shows two differences, first is that maintain rule is not rolled
back at all for @atomically, maintain just runs twice, which is
strange.
Second is that inside doit() the undo histrory for @atomically has two
more items, but this doesn't matter, because they never run.

So the question is why undo isn't triggered for normal atomic call,
but it is for task-style invoke?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.