I have a long-running process that, to save on code, is using the
Django models used in the web app to access the database.

ie.

os.environ['DJANGO_SETTINGS_MODULE'] =  'myapp.settings'
sys.path.append(os.path.abspath('/path/to/django/project'))

from myapp.subapp.models import MyModel

This works well at reducing the code requirements for the back-end
that is asynchronously populating the database from another source.
But, now and then something restarts the database. If this process it
not restarted, I then get constant exceptions:

/usr/lib/python2.3/site-packages/django/db/backends/
postgresql_psycopg2/base.py", line 50, in cursor
2008-09-03 09:19:24.170841500 InterfaceError: connection already
closed

I'm using postgres...

Now, I took a guess that if I closed the db connection, the framework
would open a new one, so I added this to each processing loop.

from django.db import connection

connection.close()

and this seems to work. No more exceptions when the db is restarted.

Now, I could have the service restarted when the db is, but I'm hoping
for a more elegant solution. I don't like either solution at the
moment, and I'm looking for recommendations.

Thanks,
Mike

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to