<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<STYLE>
BLOCKQUOTE {
        MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em; MARGIN-TOP: 0px
}
OL {
        MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
UL {
        MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
P {
        MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
BODY {
        FONT-SIZE: 10.5pt; FONT-FAMILY: 微软雅黑; COLOR: #000000; LINE-HEIGHT: 1.5
}
</STYLE>

<META name=GENERATOR content="MSHTML 11.00.9600.16518"></HEAD>
<BODY style="MARGIN: 10px">
<DIV> </DIV>
<DIV>Thank you very much.</DIV>
<DIV>I got it, I changed it to use  a defer object, not 
deferredlist</DIV>
<DIV> </DIV>
<DIV 
style="BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; BORDER-BOTTOM: medium none; PADDING-BOTTOM: 0cm; PADDING-TOP: 3pt; PADDING-LEFT: 0cm; BORDER-LEFT: medium none; PADDING-RIGHT: 0cm">
<DIV 
style="FONT-SIZE: 12px; FONT-FAMILY: tahoma; BACKGROUND: #efefef; COLOR: #000000; PADDING-BOTTOM: 8px; PADDING-TOP: 8px; PADDING-LEFT: 8px; PADDING-RIGHT: 8px">
<DIV><B>From:</B> <A 
href="mailto:exarkun@twistedmatrix.com">exarkun</A></DIV>
<DIV><B>Date:</B> 2014-03-05 23:00</DIV>
<DIV><B>To:</B> <A href="mailto:twisted-python@twistedmatrix.com">Twisted 
general discussion</A></DIV>
<DIV><B>Subject:</B> Re: [Twisted-Python] Using DeferredList, on the remote 
method get parameter of None type?</DIV></DIV></DIV>
<DIV>
<DIV>On 02:35 pm, yangyouxiu@gmail.com wrote:</DIV>
<DIV>></DIV>
<DIV>>When developing server-client software, on the client i call the method 
</DIV>
<DIV>>getTrafficDate, but on the server end, i got nio is </DIV>
<DIV>>None(d2=d.addCallback(lambda object: </DIV>
<DIV>>object.callRemote("getNIOTrafficInfo", node, nio)))</DIV>
<DIV>>,so, what's the key point?</DIV>
<DIV>></DIV>
<DIV>>[snip]</DIV>
<DIV>>        for interface in 
interfaces:</DIV>
<DIV>>            nio= 
</DIV>
<DIV>>self.interfacenio_dict[node]['interfaceinfo'][interface]</DIV>
<DIV>>            if 
nio is not None:</DIV>
<DIV>>                
if 'nio_tap' in nio or 'NIO_NF_tap' in nio:</DIV>
<DIV>>                    
d= globals.perspective.callRemote('getServerRoot')</DIV>
<DIV>>                    
d2=d.addCallback(</DIV>
<DIV>>                        
lambda object:</DIV>
<DIV>>                            
object.callRemote("getNIOTrafficInfo", node, </DIV>
<DIV>>nio))</DIV>
<DIV>>[snip]</DIV>
<DIV> </DIV>
<DIV>The value of `nio` varies for each iteration of the loop.  The value 
of </DIV>
<DIV>`nio` isn't passed to the getNIOTrafficInfo remote method until the `d` 
</DIV>
<DIV>Deferred fires - this will almost certainly be only after the loop </DIV>
<DIV>finishes (since it depends on network traffic which will only happen </DIV>
<DIV>after this method returns).</DIV>
<DIV> </DIV>
<DIV>So all of the remote calls will be made with whatever value `nio` has on 
</DIV>
<DIV>the last iteration of the loop.  This is just how scopes work in 
Python. </DIV>
<DIV>Consider this simplified example:</DIV>
<DIV>>>>def foo():</DIV>
<DIV>...     functions = []</DIV>
<DIV>...     for i in range(3):</DIV>
<DIV>...         
functions.append(lambda: i)</DIV>
<DIV>...     for f in functions:</DIV>
<DIV>...         print f()</DIV>
<DIV>...</DIV>
<DIV>>>>foo()</DIV>
<DIV>2</DIV>
<DIV>2</DIV>
<DIV>2</DIV>
<DIV>>>></DIV>
<DIV> </DIV>
<DIV>Jean-Paul</DIV>
<DIV> </DIV>
<DIV>_______________________________________________</DIV>
<DIV>Twisted-Python mailing list</DIV>
<DIV>Twisted-Python@twistedmatrix.com</DIV>
<DIV>http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</DIV></DIV></BODY></HTML>