[Twisted-Python] Using DeferredList, on the remote method get parameter of None type?
yangyouxiu
yangyouxiu at gmail.com
Fri Mar 7 00:42:38 MST 2014
Thank you very much.
I got it, I changed it to use a defer object, not deferredlist
From: exarkun
Date: 2014-03-05 23:00
To: Twisted general discussion
Subject: Re: [Twisted-Python] Using DeferredList, on the remote method get parameter of None type?
On 02:35 pm, yangyouxiu at gmail.com wrote:
>
>When developing server-client software, on the client i call the method
>getTrafficDate, but on the server end, i got nio is
>None(d2=d.addCallback(lambda object:
>object.callRemote("getNIOTrafficInfo", node, nio)))
>,so, what's the key point?
>
>[snip]
> for interface in interfaces:
> nio=
>self.interfacenio_dict[node]['interfaceinfo'][interface]
> if nio is not None:
> if 'nio_tap' in nio or 'NIO_NF_tap' in nio:
> d= globals.perspective.callRemote('getServerRoot')
> d2=d.addCallback(
> lambda object:
> object.callRemote("getNIOTrafficInfo", node,
>nio))
>[snip]
The value of `nio` varies for each iteration of the loop. The value of
`nio` isn't passed to the getNIOTrafficInfo remote method until the `d`
Deferred fires - this will almost certainly be only after the loop
finishes (since it depends on network traffic which will only happen
after this method returns).
So all of the remote calls will be made with whatever value `nio` has on
the last iteration of the loop. This is just how scopes work in Python.
Consider this simplified example:
>>>def foo():
... functions = []
... for i in range(3):
... functions.append(lambda: i)
... for f in functions:
... print f()
...
>>>foo()
2
2
2
>>>
Jean-Paul
_______________________________________________
Twisted-Python mailing list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20140307/99e1ac35/attachment-0002.html>
More information about the Twisted-Python
mailing list