Speaking at a high level, I don't see any reason why a background thread 
holding a persistent connection object in memory shouldn't work. In fact, 
I'm a little curious why the globals lookup is failing you with a timeout 
at all - it doesn't seem clear how or why this would happen. What kind of 
timeout is this, on mongo, on your user's request, within GAE, etc.? Is it 
possible that you see a coincidental timeout when reaching your DB, but the 
client 
object <http://api.mongodb.org/python/current/api/pymongo/mongo_client.html> is 
well-retrieved from globals?

The advice to modify the mongodb connector might be useful or relevant, 
although I personally can't say at this moment without debugging this 
situation more to see if that's a cause. It could be that this is expected 
behaviour given certain configuration steps or state conditions, which then 
results in the "timeout" but is ultimately avoidable through some means 
without changing anything in the mongo connector.

On Wednesday, November 4, 2015 at 2:39:17 AM UTC-5, Minie Takalova wrote:
>
> Hello
>
> I'am trying to build application on GAE which use MongoDB hosted at 
> Mongolab provider.
> Connection work, if I made new connection every request, but if I want to 
> reuse once established connection, GAE freeze and die on timeout.
> I believe that exist some simple way, how to do that such simple task.
>
>
> -----  This is woring, but open new connection every request: ------
> def get_database_connection():
>     client = pymongo.MongoClient(MONGO_URI)
>     DBCONN = client.get_default_database()
>     return DBCONN
>
> DBCON = get_database_connection()
>  ... do something usefull with DBCONN ...
>  ... not store connection anywhere ....
>  ... end request ....
>
>
> ---- This freeze GAE and die on timeout ---
> def get_database_connection():
>     if "DBCONN" in globals():             # look for open connection in 
> instance memory
>         return globals()["DBCONN"]
>     client = pymongo.MongoClient(MONGO_URI)
>     DBCONN = client.get_default_database()
>     globals()["DBCONN"] = DBCONN  # store connection to instance memory
>     return DBCONN
>
> DBCONN = get_database_connection()
>  ... do something usefull with DBCONN ...
>  ... end request .... 
>
> --------
>
> Probably GAE module with backend thread can be uset to keep connection 
> open in separate thread, but after many hours I can“t find working solution.
> Hope somebody can experience with this usecase and can help me. Also link 
> to well-tried solution will be helpfull. 
>
> Have a nice day.
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/a21825f7-2c81-40b8-b7c1-2f4c6da61302%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to