hello all, together with my Djano app, I am using an independently-
running python scripts, using Django's ORMs. It's running like a
daemon, check one table in DB, and calls function at pre-set time. The
main codes are like:

def main_daemon():
  for event in
Daemon_Event.objects.filter(event_occur_time__lte=datetime.datetime.now()
+datetime.timedelta(seconds=60)): #get all daemon event which will
occur within 1 min.
      s = (event.event_occur_time-datetime.datetime.now()).seconds
      from django.db import connection
      connection.close()
      sleep(s)
      event_handler(event)

def event_handler(event):
   ###something to deal with the event
   print event.related_model_set.get() #for test

And because the Web users can delete events he started, if I don't
use
   from django.db import connection
   connection.close()
when one event is in the sleep(s) time, and user deletes that event,
then the event_handler(event) will result something strange ( but no
programme error...). for example, after user delete one event, I can't
see the record in database table, but in event_handler(event), the
"print" will still print out the related model object.

so, I added the connection.close(), then the "print" assert exception
as objects doesn't exist, as I expected.

What I want to know is that: before sleep(s), I closed the connect,
and does is re-open database connection automaticly in
event_handler()? is it safe to use like this?

btw, the main_daemon is under transaction.manually_commit().

thanks a lot in advance.

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