I have a normal Django site. In addition, there is another twisted process that listens for Jabber presence notifications and updates Django DB using Django ORM.
So far this works, since I just invoke the appropriate Django models (after setting the settings environment correctly). This, however, blocks the Twisted app, which I don't want.
Since I'm new to twisting, I don't know what the best way would be to access Django DB (via its ORM) in a non-blocking way using pending events.
- Delayed generator?
- twisted.enterprise.adbapi? (bypass ORM?)
- ???
If the presence message is parsed, I want to save in Django DB that the user with jid_str is online / offline (using the Django UserProfile model). I am doing this with this function:
def django_useravailable(jid_str, user_available): try: userhost = jid.JID(jid_str).userhost() user = UserProfile.objects.get(im_jabber_name=userhost) user.im_jabber_online = user_available user.save() return jid_str, user_available except Exception, e: print e raise jid_str, user_available,e
I am currently calling it with:
d = threads.deferToThread(django_useravailable, from_attr, user_available) d.addCallback(self.success) d.addErrback(self.failure)
python django twisted deferred-execution
blaf
source share