Hi, you need add "grid" to lambda arguments, f = lambda _, grip=grip:self.gotDataBin(_, grid)
On Wed, Jan 25, 2012 at 6:04 PM, Tech Aficionado1743 <techaficionado1...@gmail.com> wrote: > Hello, can anyone help ? > i can't understand why, in the piece of code below (S1), > the parameter (grid) passed to the callback is the same, > while i have 2 grid, 2 deferred and 2 lambda. > The source S2 is working (2 different grid), but inelegant... > > Thank you. > > > #----------- S1 ------------------------ > def OnSubscribe(self): > for pool, grid in self.grids.items(): > print 'grid = ',grid > d = self.frame.dbpoolMiddle.runQuery(allSelect.stmts['Set0'], > (pool, self.frame.ctxName)) > print 'deferred = ', d > f = lambda _:self.gotDataBin(_, grid) > print 'lambda =', f > d.addCallback(f) > > def gotDataBin(self, result, grid): > print 'callback = ', grid > grid.ReplaceRowsFromSQL(result) > > #----------- Output S1 ---------------- > > grid = <cfm.wx.CfmGrid.CfmGrid; proxy of <Swig Object of type 'wxGrid *' at > 0x2d61b48> > > deferred = <Deferred at 0x2e6bd28> > lambda = <function <lambda> at 0x02DCDCF0> > > grid = <cfm.wx.CfmGrid.CfmGrid; proxy of <Swig Object of type 'wxGrid *' at > 0x2d5e788> > > deferred = <Deferred at 0x2e6bdc8> > lambda = <function <lambda> at 0x02DCDCB0> > > callback = <cfm.wx.CfmGrid.CfmGrid; proxy of <Swig Object of type 'wxGrid > *' at 0x2d5e788> > # expected to get 1st grid here: 0x2d61b48, not two times > 2nd grid > callback = <cfm.wx.CfmGrid.CfmGrid; proxy of <Swig Object of type 'wxGrid > *' at 0x2d5e788> > > > #----------- S2 ------------------------ > def OnSubscribe(self): > for pool, grid in self.grids.items(): > d = self.frame.dbpoolMiddle.runQuery(allSelect.stmts['Set0'], > (pool, self.frame.ctxName)) > > def toto(grid): > d.addCallback(lambda _:self.gotDataBin(_, grid)) > > toto(grid) > > def gotDataBin(self, result, grid): > print 'callback = ', grid > grid.ReplaceRowsFromSQL(result) > > > _______________________________________________ > Twisted-Python mailing list > Twisted-Python@twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python