Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Simplify code working on top of gen.engin

Received: by 10.101.151.37 with SMTP id d37mr1912972ano.26.1350248112876;
        Sun, 14 Oct 2012 13:55:12 -0700 (PDT)
X-BeenThere: python-tornado@googlegroups.com
Received: by 10.236.154.170 with SMTP id h30ls6865971yhk.7.gmail; Sun, 14 Oct
 2012 13:55:09 -0700 (PDT)
Received: by 10.236.192.168 with SMTP id i28mr1209292yhn.7.1350248109415;
        Sun, 14 Oct 2012 13:55:09 -0700 (PDT)
Date: Sun, 14 Oct 2012 13:55:09 -0700 (PDT)
From: "A. Jesse Jiryu Davis" <ajesseda...@gmail.com>
To: python-tornado@googlegroups.com
Message-Id: <eb7b6d7c-ae5f-4c68-8093-0fb863a58dd9@googlegroups.com>
In-Reply-To: <CAJZrG8izisB7bzYz+OwbJ-On=kjQq_y3NjpoFWVYaEqHZ-AGwA@mail.gmail.com>
References: <CAJZrG8j5ExzPfrgj-m6M7x351Gzx9iCHvbMtkEmZG_v8MmXzZA@mail.gmail.com>
 <CAJZrG8izisB7bzYz+OwbJ-On=kjQq_y3NjpoFWVYaEqHZ-AGwA@mail.gmail.com>
Subject: Re: Simplify code working on top of gen.engin
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_317_7687493.1350248109087"

------=_Part_317_7687493.1350248109087
Content-Type: multipart/alternative; 
	boundary="----=_Part_318_19137751.1350248109087"

------=_Part_318_19137751.1350248109087
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

I like this idea. So with your example:

@gen.async
def handle(param1, param2):
    ....

The decorated function handle gets an optional callback kwarg, perhaps?:

handle(param1, param2, callback=None)

This way I can either choose to block on it:

yield gen.Task(handle, 'a', 'b')
# This line runs after handle completes

or not:

handle('a', 'b')
# This line runs immediately without waiting for handle

On Sunday, October 14, 2012 7:40:21 AM UTC-4, Serge S. Koval wrote:
>
> 3. Callback won't be exposed to the function and will be called by the 
>> runner. No need to keep queue of "not called" callbacks for safety reasons 
>> - there's guarantee that callback will be called;
>>
> Minor correction - with current tornado.gen implementation it is possible 
> to skip calling callback function and it won't trigger the error:
>
> Consider following:
>
> @gen.engine
> def handle(a, callback):
>   b = yield gen.Task(fetch, a)
>
>   if b == '1':
>     callback('hi')
>
> @gen.engine
> def test():
>   yield gen.Task(handle, 'http://www.google.com/')
>   print 'hi'
>
> In this example, 'hi' will be never printed if fetch does not return 1. 
> Sure, it is programmers concern to make sure that all terminating branches 
> should run callback, but if that's decorator responsibility to run callback 
> function, this type of error should not happen.
>
> Serge.
>

------=_Part_318_19137751.1350248109087
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

I like this idea. So with your example:<br><br><div><span style=3D"font-fam=
ily: courier new,monospace;">@gen.async</span></div><div><span style=3D"fon=
t-family: courier new,monospace;">def handle(param1, param2):<br>&nbsp;&nbs=
p;&nbsp; ....</span><br><br>The decorated function <span style=3D"font-fami=
ly: courier new,monospace;">handle</span> gets an optional callback kwarg, =
perhaps?:<br><br><span style=3D"font-family: courier new,monospace;">handle=
(param1, param2, callback=3DNone)<br></span></div><br>This way I can either=
 choose to block on it:<br><br><span style=3D"font-family: courier new,mono=
space;">yield gen.Task(handle, 'a', 'b')<br># This line runs after handle c=
ompletes<br></span><br>or not:<br><span style=3D"font-family: courier new,m=
onospace;"><br>handle('a', 'b')<br># This line runs immediately without wai=
ting for handle</span><br><br>On Sunday, October 14, 2012 7:40:21 AM UTC-4,=
 Serge S. Koval wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div cla=
ss=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div>3. Callback won't be=
 exposed to the function and will be called by the runner. No need to keep =
queue of "not called" callbacks for safety reasons - there's guarantee that=
 callback will be called;</div>
</blockquote><div>Minor correction - with current tornado.gen implementatio=
n it is possible to skip calling callback function and it won't trigger the=
 error:</div><div><br></div><div>Consider following:</div><div><br>
</div><div>@gen.engine</div><div>def handle(a, callback):</div><div>&nbsp; =
b =3D yield gen.Task(fetch, a)</div><div><br></div><div>&nbsp; if b =3D=3D =
'1':</div><div>&nbsp; &nbsp; callback('hi')</div><div><br></div><div>@gen.e=
ngine</div>
<div>def test():</div><div>&nbsp; yield gen.Task(handle, '<a href=3D"http:/=
/www.google.com/" target=3D"_blank">http://www.google.com/</a>')</div><div>=
&nbsp; print 'hi'</div><div><br></div><div>In this example, 'hi' will be ne=
ver printed if fetch does not return 1. Sure, it is programmers concern to =
make sure that all terminating branches should run callback, but if that's =
decorator responsibility to run callback function, this type of error shoul=
d not happen.</div>
<div><br></div><div>Serge.</div></div>
</blockquote>
------=_Part_318_19137751.1350248109087--

------=_Part_317_7687493.1350248109087--