<div>Hello, can anyone help ?</div><div>i can't understand why, in the piece of code below (S1),</div><div>the parameter (grid) passed to the callback is the same, </div><div>while i have 2 grid, 2 deferred and 2 lambda.</div>
<div>The source S2 is working (2 different grid), but inelegant...</div><div><br></div><div>Thank you.</div><div><br></div><div><br></div><div>#----------- S1 ------------------------</div><div> def OnSubscribe(self):</div>
<div> for pool, grid in self.grids.items():</div><div> print 'grid = ',grid</div><div> d = self.frame.dbpoolMiddle.runQuery(allSelect.stmts['Set0'], (pool, self.frame.ctxName))</div>
<div> print 'deferred = ', d</div><div> f = lambda _:self.gotDataBin(_, grid)</div><div> print 'lambda =', f</div><div> d.addCallback(f)</div><div><br></div><div>
def gotDataBin(self, result, grid):</div><div> print 'callback = ', grid</div><div> grid.ReplaceRowsFromSQL(result)</div><div><br></div><div>#----------- Output S1 ----------------</div><div><br>
</div><div>grid = <cfm.wx.CfmGrid.CfmGrid; proxy of <Swig Object of type 'wxGrid *' at 0x2d61b48> ></div><div>deferred = <Deferred at 0x2e6bd28></div><div>lambda = <function <lambda> at 0x02DCDCF0></div>
<div><br></div><div>grid = <cfm.wx.CfmGrid.CfmGrid; proxy of <Swig Object of type 'wxGrid *' at 0x2d5e788> ></div><div>deferred = <Deferred at 0x2e6bdc8></div><div>lambda = <function <lambda> at 0x02DCDCB0></div>
<div><br></div><div>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</div><div>callback = <cfm.wx.CfmGrid.CfmGrid; proxy of <Swig Object of type 'wxGrid *' at 0x2d5e788> ></div>
<div><br></div><div>#----------- S2 ------------------------</div><div> def OnSubscribe(self):</div><div> for pool, grid in self.grids.items():</div><div> d = self.frame.dbpoolMiddle.runQuery(allSelect.stmts['Set0'], (pool, self.frame.ctxName))</div>
<div> </div><div> def toto(grid):</div><div> d.addCallback(lambda _:self.gotDataBin(_, grid))</div><div> </div><div> toto(grid)</div><div><br></div><div> def gotDataBin(self, result, grid):</div>
<div> print 'callback = ', grid</div><div> grid.ReplaceRowsFromSQL(result)</div><div><br></div>