<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body dir="ltr" bgcolor="#ffffff" text="#000000">
<br>
<p style="margin-bottom: 0cm; margin-top: 0pt;">-------- Original
Message  --------</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">From: Andrea Spadaccini
<a class="moz-txt-link-rfc2396E" href="mailto:a.spadaccini@catania.linux.it">&lt;a.spadaccini@catania.linux.it&gt;</a><br>
<br>
</p>
<blockquote cite="mid20080221120817.42a3924c@catania.linux.it"
 type="cite">
  <pre wrap="">Ciao a tutti,
  </pre>
</blockquote>
Ciao<br>
<br>
<blockquote cite="mid20080221120817.42a3924c@catania.linux.it"
 type="cite">
  <pre wrap="">mi sono trovato ad utilizzare una libreria[1] che si basa su twisted, e non
conoscendo bene quest'ultimo mi trovo un po' in difficoltà.
  </pre>
</blockquote>
Con twisted all'inizio è sempre così :-)<br>
<br>
<blockquote cite="mid20080221120817.42a3924c@catania.linux.it"
 type="cite">
  <pre wrap="">
Io devo semplicemente richiamare tre volte il metodo getVariable, per prelevare
tre variabili differenti, utilizzare queste tre variabili per alcune operazioni
su DB ed infine richiamare N volte il metodo setVariable.
  </pre>
</blockquote>
<br>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Non conosco
gatherResult, può darsi che sia comunque utile al tuo caso.</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Puoi comunque far così:</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  ..<br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  def
extract_result(res_list):</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">    #res_list = ((1 if
ok or 0 on error, res_dd1), (1 if ok or 0 on error, res_dd2), .. )</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">    result = [x[1] for
x in res_list]</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  <br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  def
accedi_al_db(results):</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">    def _(results):</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">      #qui fai ciò che
vuoi sul database</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">      #per la trasact</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">      return valori<br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">    return
deferToThread(_, results) </p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">    #oppure decori con
@transact, vedi Stiq</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">    #operare in un
altro thread è comodo perche il db è lento</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  def set_vars(valori):<br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">    return DeferredList([setVariable(var)
for var in results])<br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  dvar1 =getVariable(..)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  dvar2 =getVariable(..)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  dvar2 =getVariable(..)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  dd =
DeferredList([dvar1, dvar2, dvar3])</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"> 
dd.addCallback(extract_result)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"> 
dd.addCallback(accedi_al_db)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">  dd.addCallback(lambda
x:set_vars(x))</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">la deferredlist la
trovi qui</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><a class="moz-txt-link-freetext" href="http://twistedmatrix.com/projects/core/documentation/howto/defer.html#auto7">http://twistedmatrix.com/projects/core/documentation/howto/defer.html#auto7</a></p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Rigorosamente non
testato. </p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">In particolare la
lambda all'ultima riga credo sia necessaria per poter fare gestire
correttamente la deferred alla callback, cioè: la callback ha come
argomento una deferred... <br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Scrivendo solo</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">...<br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">dd.addCallback(set_vars)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
credo che il risultato della deferred 'dd' sia difficilmente gestibile,
anche se le variabili vengono correttamente settate</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
<br>
</p>
<blockquote cite="mid20080221120817.42a3924c@catania.linux.it"
 type="cite">
  <pre wrap="">Qualcuno può darmi una mano?
Grazie in anticipo!
  </pre>
</blockquote>
Spero di esserti stato d'aiuto<br>
Anche io sono interessato a vedere del codice migliore del mio :-)<br>
<br>
Ciao<br>
Alessandro<br>
<br>
</body>
</html>