<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
This example shows what i want:<br>
<pre class="wiki">@defer.inlineCallbacks
def create_audio_link(tel, addr1, addr2):
try:
connection1, connection2 = yield (tel.connect(addr1), tel.connect(addr2))
except ConnectionError, exc:
... some error work ...
else:
return tel.create_audiolink(connection1, connection2)
</pre>
At now we can do this with DeferredList but it is complex (compare with
first example):<br>
<pre class="wiki">@defer.inlineCallbacks
def create_audio_link(tel, addr1, addr2):
try:
try:
r = yield DeferredList([tel.connect(addr1), tel.connect(addr2)], fireOnOneErrback=1, consumeErrors=1)
except FirstError, exc:
raise exc.subFailure.value
else:
connection1, connection2 = tuple(_r for _s, _r in r)
except ConnectionError, exc:
... some error work ...
else:
return tel.create_audiolink(connection1, connection2)
</pre>
<div dir="ltr" style="">
<div id="tts_button" title="Прослушать этот перевод"
style="display: block;" class=" "><object
type="application/x-shockwave-flash"
data="http://www.gstatic.com/translate/sound_player2.swf"
id="tts_flash" width="18" height="18"><param
value="http://www.gstatic.com/translate/sound_player2.swf" name="movie"><param
value="sound_name=translate_tts%3Fq%3DPython%2BURL%2B%25D1%2580%25D0%25B0%25D0%25B7%25D0%25B1%25D0%25BE%25D1%2580%25D0%25B0%26tl%3Dru&sound_name_cb=_TTSSoundFile"
name="flashvars"><param value="transparent" name="wmode"><param
value="always" name="allowScriptAccess"></object></div>
<span id="result_box" class="short_text"><span
style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 0);"
title="">Approximate</span></span> solution (idea) is patch in
defer.py:<br>
</div>
<pre class="wiki">def _inlineCallbacks(result, g, deferred):
... skipped ...
if isinstance(result, Deferred):
# a deferred was yielded, get the result.
... skipped ...
waiting[0] = True
waiting[1] = None
if isinstance(result, tuple):
# a tuple was yielded, get the result.
result = DeferredList(result, fireOnOneErrback=1, consumeErrors=1)
def gotResult(r):
if isinstance(r, failure.Failure):
r = r.value.subFailure
else:
r = tuple(_r for _s, _r in r)
if waiting[0]:
waiting[0] = False
waiting[1] = r
else:
_inlineCallbacks(r, g, deferred)
result.addBoth(gotResult)
if waiting[0]:
# Haven't called back yet, set flag so that we get reinvoked
# and return from the loop
waiting[0] = False
return deferred
result = waiting[1]
# Reset waiting to initial values for next loop. gotResult uses
# waiting, but this isn't a problem because gotResult is only
# executed once, and if it hasn't been executed yet, the return
# branch above would have been taken.
waiting[0] = True
waiting[1] = None
return deferred
</pre>
I post this as ticket but was redirected to mailing-list<br>
<a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://twistedmatrix.com/trac/ticket/4627">http://twistedmatrix.com/trac/ticket/4627</a><br>
<br>
</body>
</html>