On 05/23/06 21:20, Christian Schneider wrote: > Hi all, > > has anyone any experiences as to using django from a twisted application? > I'm asking because I had some issues with MySQL as in crashing connections > and too many database handles open. As far as I can tell, which isn't very > far, my twisted application is running in just one thread, so I'm not sure > where that is coming from. Is it possible for django to have more than one > database handle open for a single process? >
Hi Chris The attached file is a small 'proof of concept' test I once did. Maybe it gives you some ideas. Also have a look at [1]. [1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439358 hth cheers Steven --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
""" @see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439358 """ import sys import os sys.path.append('/home/me/ws/python/django') sys.path.append('/home/me/ws/python') os.environ['DJANGO_SETTINGS_MODULE'] = 'djportal.settings' def deferred(*args): """deferred(object) -> twisted.internet.defer.Deferred instance Run a potentially blocking callable object in a thread.""" # initialized on first call from twisted.python import threadable threadable.init(1) from twisted.internet.threads import deferToThread global deferred deferred = deferToThread.__get__ return deferred(*args) @deferred def get_active_portlets(): data = {} from portal.models import Portlet for model in Portlet.objects.filter(status=True): data[model.id] = (model.name, model.application, model.module, model.portlet_class) # simulate extra long operation import time time.sleep(2) return data def running(): "Prints a few dots on stdout while the reactor is running." sys.stdout.write(".") sys.stdout.flush() reactor.callLater(.1, running) def print_data(data): "got a result, do something with it" for record in data.items(): print record def print_error(error): "got a error, show it" print error from twisted.internet import reactor def main(): d = get_active_portlets() d.addCallback(print_data) d.addErrback(print_error) reactor.callLater(.1, running) # shutdown the reactor after 5 seconds reactor.callLater(5, reactor.stop) reactor.run() if __name__ == "__main__": main()