Re: django database access with threadpool

2007-09-11 Thread johnny

I can someone tell me how the database connection is handled for
threads.  Do I have to pass conneciton object to each threads?

All I am doing is this:

@threadpool(pool)
def process(i):
print 'threadpool %i enter' % i

p = Profile.objects.get(id=i)
p.status ="sent"
p.save()

print 'threadpool %i exit' % i

Threads does save modified Profile object to the database, but after
saving it, threads just stays there.  Threads seem like they are
waiting for something. It doesn't do "print threadpool exit".


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



django database access with threadpool

2007-09-11 Thread johnny

I am implementing a backend python script that updates the database.
It uses threadpool(http://snippets.dzone.com/posts/show/4425#related).
Threadpool size is 3.  When records are returned, eg. 10 records, 3
threads are created, then the threads update the database, but doesn't
seem to do
task_done().  Three threads that were created initially, just hangs.
I am running FC7 with python2.5.

class ProfileManager(models.Manager):
def not_confirmed():

c = connection.cursor()
c.execute("select * from profile_profile where status
='waiting confirmation'")
return c.fetchall()

backend_threaded.py:

#! /usr/bin/env python
from apps.utils.threadpool import *
#Pyhton ThreadPool: http://snippets.dzone.com/posts/show/4425#related
from time import sleep
import datetime

from os import environ
environ['DJANGO_SETTINGS_MODULE'] = "settings"
from settings import *
from apps.profile.models import *

pool = Pool(3)

@threadpool(pool)
def process(i):
print 'threadpool %i enter' % i

p = Profile.objects.get(id=i)
p.status ="sent"
p.save()

print 'threadpool %i exit' % i

def main():

rs = Profile.objects.not_confirmed()
print rs
for l in rs:
process(l[0])
pool.join()

if __name__=="__main__":
main()


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