Monday 15 July 2013

python - exceptions raised from within a urlfetch callback -



python - exceptions raised from within a urlfetch callback -

when performing async urlfetch calls callback , within tasklet, seems exceptions raised within callback don't propagate wrapping tasklet.

example code:

def cb() : raise exception, 'just test' rpc = urlfetch.create_rpc(callback = cb) @ndb.tasklet def t() : seek : response = yield urlfetch.make_fetch_call(rpc, 'http://...') except : print 'an error occured' raise ndb.return t().get_result()

in code above, executed dev server, "just test" exception doesn't caught within tasklet; ie. instead of error message beingness output console i'm getting "just test" exception reported.

if there's generic urlfetch exception related make_fetch_call (such downloaderror in case of bad url), it's beingness handled properly.

is there way grab callback-generated exceptions within tasklet in such situation? or maybe should behavior considered bug?

thanks.

i've created sample project illustrate right way this.

while reading code, you'll find lot of benefit reading comments , cross-referencing docs on tasklets , rpc.make_fetch_call().

some of confusing aspects of fact ndb tasklets utilize exceptions indicate homecoming values (even if successful, should raise ndb.return (true), making exception handling hard tiptoe around), , fact exceptions in callback needs caught when phone call wait() on rpc future object returned t(), while exceptions in url fetch need caught within t() when yield rpc.make_fetch_call(). there may way latter using rpc.check_success(), that'll hacking figure out.

i hope find source helpful, , hope learned lesson avoiding using exceptions indicate generator done...

python google-app-engine asynchronous urlfetch

No comments:

Post a Comment