<div class="gmail_quote">2009/5/11 Jean-Paul Calderone <span dir="ltr"><<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Mon, 11 May 2009 19:49:19 +0200, Luigi Conte <<a href="mailto:luigiandcosolutions@gmail.com">luigiandcosolutions@gmail.com</a>> wrote:<br>
><br>
> [snip]<br>
<div class="im">>in my script I have to use connect method and then I have to do some<br>
>operations first of calling the start method<br>
>1) start connection<br>
><br>
> def startConnection(self):<br>
> d = my_api.connect(self.ctrl_ip, self.ctrl_port, self.user,<br>
>self.pwd)<br>
> d.addCallback(self.postConnection)<br>
<br>
</div>Since you omitted the definition of postConnection, I have no way to know<br>
what this does.<br>
<div class="im"><br>
> d.addErrback(twisted.python.log.err)<br>
<br>
</div>Regardless, this is the wrong place to insert this errback. You should read<br>
the Deferred documentation to learn what consequence it will have on your<br>
program's flow.<br>
<br>
<a href="http://twistedmatrix.com/projects/core/documentation/howto/defer.html" target="_blank">http://twistedmatrix.com/projects/core/documentation/howto/defer.html</a> is<br>
probably a good place to start.<br>
<div class="im"><br>
> print "Connection added"<br>
> return d<br>
>2) operation before starting a virtual machine:<br>
>def newVMCfg(self, new_vms_cfg):<br>
> #...<br>
> #some operations<br>
> #if condition valid I try to start the virtual machine<br>
> # is this the correct way to pass args to the start<br>
>method?<br>
> d = self.d.addCallback(self.startVM,(new_vm,<br>
>self.lnms[i])<br>
> print "started vm %s"%new_vm<br>
> return d<br>
><br>
>in the main process I call them as:<br>
>d = startConnection()<br>
>d.addCallback(newVMCfg, arg)<br>
><br>
>Is it correct? Because the process stops at the first method called: I see<br>
>only "connection added".<br>
<br>
</div>That should indicate to you that something is going wrong after that print<br>
statement is reached. So examine what your program tries to do after that<br>
point. You may want to use a debugger. You may want to try writing some<br>
unit tests.<br>
<div><div></div><div class="h5"><br>
Jean-Paul<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a></div></div></blockquote><div><br>I looked at the documentation and I understood something about defferd and callbacks. I edited my code but it does nothing...<br>
I'm going to explain the scenario and what I want to do:<br>- there is an api that provides some methods (connect, start, disconnect).<br>- all those methods return a deferred object<br>- I have an object that first tries to connect, then reads a file and calls the start method many times in a loop cicle of his method.<br>
<br>I want to use the connect and wait until I'm really connected. How can I do this using the deferred object that the api returns to me?<br>I want to do the same thing each time I call the start method from the api: I want to wait the completing of start operation before doing another start invocation.<br>
<br>so I do:<br>in the main process:<br> d = gest.connettiCLI_to_CTRL()<br><br>in gest class I have:<br> def connettiCLI_to_CTRL(self):<br> d = api.connect(self.ctrl_ip, self.ctrl_port, self.user, self.pwd)<br>
d.addCallback(self.cbConnected)<br> return d<br><br> def cbConnected(self, connectResult):<br> return self.postConnection()<br><br> def postConnection(self):<br> # I do something but I don't call api's methods here<br>
# then I go to the next step returning the next method<br> return self.interpretaNewVMCfg(self.vms_cfg)<br><br> def interpretaNewVMCfg(self, new_vms_cfg):<br> for i in candidati:<br> #start operation in loop<br>
#here I want to control each start operation<br> d = api.startVM(new_vm, self.lnms[i])<br> return d<br><br>thank you so much<br><br></div></div><br>