From: Randall S. <ra...@tn...> - 2005-12-02 21:29:21
|
How do you get threads to use sqlhub? In the following code, I created an instance of Person in the main process and then attempted two instance in threads. The first succeeded and the second to failed saying there was no connection defined. I'm ultimately going to run my app on webkit, which is threaded. import threading from sqlobject import * cns="postgresql://me:mine@localhost/test" con = connectionForURI(cns) sqlhub.threadConnection = con threads = [] class Person(SQLObject): firstName = StringCol() middleInitial = StringCol(length=1, default=None) lastName = StringCol() Person.createTable(ifNotExists=True) person = Person(firstName='Randall', middleInitial='B', lastName='Smith', ) print person class MyThread(threading.Thread): def run(self): person = Person(firstName='Randall', middleInitial='B', lastName='Smith', ) ##print self.getName(), sqlhub.getConnection() for threadname in range(2): threads.append(MyThread(name=threadname + 1).start()) |