[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-14 Thread Alexander Kojevnikov

Joseph,

You can try this code:

def put(self):
count = 0
while True:
try:
return db.Model.put(self)
except:
count += 1
if count == 3:
raise

Cheers,
Alex
--
www.muspy.com

On Jan 15, 4:09 am, "bowman.jos...@gmail.com"
 wrote:
> I have the basics, which are posted below. However, this is where I'm
> realizing I'm still very new at learning python. What I'd like to do
> it only catch the timeout error for the retries, and at the end of the
> retries go ahead and return the timeout error, as if it's failed 3
> times, I'm going to assume it will keep failing and it's up to the
> application to handle that.
>
> class ROTModel(db.Model):
>     """
>     Retry On Timeout Model. This model exists to override the put
> method of
>     db.Model in order to retry the put operation when a timeout error
> is encountered.
>     """
>     def put(self):
>         count = 0
>         while count < 3:
>             try:
>                 return db.Model.put(self)
>             except:
>                 count += 1
>         else:
>             raise datastore._ToDatastoreError()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-14 Thread bowman.jos...@gmail.com

Is there any way to catch the timeout error specifically? That way it
doesn't bother to retry if something else is the problem.

On Jan 14, 5:53 pm, Alexander Kojevnikov 
wrote:
> Joseph,
>
> You can try this code:
>
>     def put(self):
>         count = 0
>         while True:
>             try:
>                 return db.Model.put(self)
>             except:
>                 count += 1
>                 if count == 3:
>                     raise
>
> Cheers,
> Alex
> --www.muspy.com
>
> On Jan 15, 4:09 am, "bowman.jos...@gmail.com"
>
>  wrote:
> > I have the basics, which are posted below. However, this is where I'm
> > realizing I'm still very new at learning python. What I'd like to do
> > it only catch the timeout error for the retries, and at the end of the
> > retries go ahead and return the timeout error, as if it's failed 3
> > times, I'm going to assume it will keep failing and it's up to the
> > application to handle that.
>
> > class ROTModel(db.Model):
> >     """
> >     Retry On Timeout Model. This model exists to override the put
> > method of
> >     db.Model in order to retry the put operation when a timeout error
> > is encountered.
> >     """
> >     def put(self):
> >         count = 0
> >         while count < 3:
> >             try:
> >                 return db.Model.put(self)
> >             except:
> >                 count += 1
> >         else:
> >             raise datastore._ToDatastoreError()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-14 Thread Alexander Kojevnikov

> Is there any way to catch the timeout error specifically? That way it
> doesn't bother to retry if something else is the problem.
>
Sure, just replace "except" with "except db.Timeout"
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-15 Thread bowman.jos...@gmail.com



On Jan 14, 11:11 pm, Alexander Kojevnikov 
wrote:
> > Is there any way to catch the timeout error specifically? That way it
> > doesn't bother to retry if something else is the problem.
>
> Sure, just replace "except" with "except db.Timeout"


Oh ok.. so it is possible to catch that. It's datastore.Timeout and
not db.Timeout, right? I was confused because when I see it in the
logs I saw: raise _ToDatastoreError(err), so I wasn't sure how to
catch it since that exception covers pretty much any issue with
writing to the datastore, not just timeouts. (Sorry, I didn't start
using python until I started using appengine, so still learning here)

example:

: datastore
timeout: operation took too long.
Traceback (most recent call last):
  File "/base/data/home/apps/fanatasticweb/1.330570312771074300/common/
appenginepatch/main.py", line 26, in real_main
util.run_wsgi_app(application)
  File "/base/python_lib/versions/1/google/appengine/ext/webapp/
util.py", line 76, in run_wsgi_app
result = application(env, _start_response)
  File "/base/data/home/apps/fanatasticweb/1.330570312771074300/common/
zip-packages/django.zip/django/core/handlers/wsgi.py", line 239, in
__call__
  File "/base/data/home/apps/fanatasticweb/1.330570312771074300/common/
zip-packages/django.zip/django/core/handlers/base.py", line 67, in
get_response
  File "/base/data/home/apps/fanatasticweb/1.330570312771074300/common/
appengine_utilities/django-middleware/middleware.py", line 12, in
process_request
request.session = sessions.Session()
  File "/base/data/home/apps/fanatasticweb/1.330570312771074300/common/
appengine_utilities/sessions.py", line 207, in __init__
self.session.put()
  File "/base/python_lib/versions/1/google/appengine/ext/db/
__init__.py", line 657, in put
return datastore.Put(self._entity)
  File "/base/python_lib/versions/1/google/appengine/api/
datastore.py", line 162, in Put
raise _ToDatastoreError(err)
  File "/base/python_lib/versions/1/google/appengine/api/
datastore.py", line 1637, in _ToDatastoreError
raise errors[err.application_error](err.error_detail)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-15 Thread Alexander Kojevnikov

> Oh ok.. so it is possible to catch that. It's datastore.Timeout and
> not db.Timeout, right? I was confused because when I see it in the
> logs I saw: raise _ToDatastoreError(err), so I wasn't sure how to
> catch it since that exception covers pretty much any issue with
> writing to the datastore, not just timeouts.
>
Actually google.appengine.ext.db.Timeout and
google.appengine.api.datastore_errors.Timeout is the same class, check
google/appengine/ext/db/__init__.py, line 105.

db.Timeout is documented here [1], the one from datastore_errors is
not a part of documented public API and thus can change. It's safer to
use db.Timeout in your code.

[1] http://code.google.com/appengine/docs/datastore/exceptions.html

> (Sorry, I didn't start using python until I started using
> appengine, so still learning here)
>
Neither did I :) You can skim through the chapter of the tutorial that
covers exceptions, it's pretty short and very well written:
http://www.python.org/doc/2.5.2/tut/node10.html

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-16 Thread bowman.jos...@gmail.com

Thanks for both links. I think I need to go back over that site. That
page on exceptions was much better than the book I bought.

On Jan 15, 6:28 pm, Alexander Kojevnikov 
wrote:
> > Oh ok.. so it is possible to catch that. It's datastore.Timeout and
> > not db.Timeout, right? I was confused because when I see it in the
> > logs I saw: raise _ToDatastoreError(err), so I wasn't sure how to
> > catch it since that exception covers pretty much any issue with
> > writing to the datastore, not just timeouts.
>
> Actually google.appengine.ext.db.Timeout and
> google.appengine.api.datastore_errors.Timeout is the same class, check
> google/appengine/ext/db/__init__.py, line 105.
>
> db.Timeout is documented here [1], the one from datastore_errors is
> not a part of documented public API and thus can change. It's safer to
> use db.Timeout in your code.
>
> [1]http://code.google.com/appengine/docs/datastore/exceptions.html
>
> > (Sorry, I didn't start using python until I started using
> > appengine, so still learning here)
>
> Neither did I :) You can skim through the chapter of the tutorial that
> covers exceptions, it's pretty short and very well 
> written:http://www.python.org/doc/2.5.2/tut/node10.html
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-16 Thread Devel63

Be aware that calls to db.put() will not call your db.Model.put()
override.  So if you are trying to be efficient by making several puts
at once via db.put([objlist]), your override will not be called.

I wish I knew how to solve this, but I don't.  I hope someone can tell
both of us what the preferred method for handling a put override is.

On Jan 16, 6:16 am, "bowman.jos...@gmail.com"
 wrote:
> Thanks for both links. I think I need to go back over that site. That
> page on exceptions was much better than the book I bought.
>
> On Jan 15, 6:28 pm, Alexander Kojevnikov 
> wrote:
>
> > > Oh ok.. so it is possible to catch that. It's datastore.Timeout and
> > > not db.Timeout, right? I was confused because when I see it in the
> > > logs I saw: raise _ToDatastoreError(err), so I wasn't sure how to
> > > catch it since that exception covers pretty much any issue with
> > > writing to the datastore, not just timeouts.
>
> > Actually google.appengine.ext.db.Timeout and
> > google.appengine.api.datastore_errors.Timeout is the same class, check
> > google/appengine/ext/db/__init__.py, line 105.
>
> > db.Timeout is documented here [1], the one from datastore_errors is
> > not a part of documented public API and thus can change. It's safer to
> > use db.Timeout in your code.
>
> > [1]http://code.google.com/appengine/docs/datastore/exceptions.html
>
> > > (Sorry, I didn't start using python until I started using
> > > appengine, so still learning here)
>
> > Neither did I :) You can skim through the chapter of the tutorial that
> > covers exceptions, it's pretty short and very well 
> > written:http://www.python.org/doc/2.5.2/tut/node10.html
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: Looking for help to finish a new model to catch datastore timeouts

2009-01-16 Thread boson

On Jan 16, 11:25 am, Devel63  wrote:
> I wish I knew how to solve this, but I don't.  I hope someone can tell
> both of us what the preferred method for handling a put override is.

That was the subject of this still open thread:
http://groups.google.com/group/google-appengine/browse_thread/thread/3721e262f1975934

I suspect there will be a growing number of bugs in apps by people not
realizing their put overrides aren't actually being called.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---