On Fri, Sep 7, 2012 at 3:07 AM, Benjamin Lee <[email protected]> wrote: > Hey guys, I'm looking to manually supply a connection for a model to use. > (to take advantage of the ORM in i.e. long running django management > command). > > Basically I have some loop that is run, and only a portion of the loop > requires a connection. I'd like to return the connection back to a pool by > having some sort of manual control over the connection the ORM is using. > (The connection won't close by itself since this isn't a request/response) > > To make things more complex, it's a management command using greenlets each > of which can have their own db connection. So what I really want is, for > each greenlet, to be able return the connection back to a pool after using > django's ORM for some small portion of the greenlet's task. >
Why? Have you profiled your application and found that creating and opening database connections is too expensive? I would simply open a connection when necessary, use it until you are sure you no longer need it, and close it. If you are not concerned about the number of inactive connections, I wouldn't even close it. If you're using MySQL, which especially optimises connection times and handles inactive connections really well, I definitely wouldn't close it. There are patches out there to allow connection pooling in django. "django connection pooling" should give you a headstart. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. 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.

