<div class="gmail_quote">2009/5/11 Jean-Paul Calderone <span dir="ltr">&lt;<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>&gt;</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 &lt;<a href="mailto:luigiandcosolutions@gmail.com">luigiandcosolutions@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; [snip]<br>
<div class="im">&gt;in my script I have to use connect method and then I have to do some<br>
&gt;operations first of calling the start method<br>
&gt;1) start connection<br>
&gt;<br>
&gt;    def startConnection(self):<br>
&gt;        d = my_api.connect(self.ctrl_ip, self.ctrl_port, self.user,<br>
&gt;self.pwd)<br>
&gt;        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>
&gt;        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&#39;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>
&gt;        print &quot;Connection added&quot;<br>
&gt;        return d<br>
&gt;2) operation before starting a virtual machine:<br>
&gt;def newVMCfg(self, new_vms_cfg):<br>
&gt;       #...<br>
&gt;       #some operations<br>
&gt;       #if condition valid I try to start the virtual machine<br>
&gt;                        # is this the correct way to pass args to the start<br>
&gt;method?<br>
&gt;                        d = self.d.addCallback(self.startVM,(new_vm,<br>
&gt;self.lnms[i])<br>
&gt;                        print &quot;started vm %s&quot;%new_vm<br>
&gt;        return d<br>
&gt;<br>
&gt;in the main process I call them as:<br>
&gt;d = startConnection()<br>
&gt;d.addCallback(newVMCfg, arg)<br>
&gt;<br>
&gt;Is it correct? Because the process stops at the first method called: I see<br>
&gt;only &quot;connection added&quot;.<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&#39;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&#39;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&#39;t call api&#39;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>