On Fri, 2007-10-26 at 15:57 +0000, Luke wrote: > In one of my django apps, I need to access another database that is > unrelated to django's db. We are using psycopg to access this. There > is some code running some calculations inside the db as a shared > object, and it is tied to a connection, so we need to keep it open and > not make a new connection each time the web page is accessed. > Therefore, we need a place to store a psycopg connection object > persistently. I know there are sessions, but I think that would still > mean the destructor gets called and the connection gets closed when > the handler returns.
This sounds a bit fragile, since even if you tied the connection to the mod_python process, it could be killed off and restarted periodically (based on Apache's MaxRequestsPerChild, for example). If you need the connection to persist, tying it to anything webserver-related feels like the wrong approach. One alternative would be to create a daemon process that holds the connection. You can connect to the daemon using a named pipe or socket connection if you need to talk to it (although why not just have the daemon manage the long-running connection completely). But, at the base level, try to remove the need to hold the connection in the web-interaction portions of your code. You simply don't have enough control over their lifetimes. Regards, Malcolm -- Remember that you are unique. Just like everyone else. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---