[PonyORM-list] Running in thread ?

Tomislav Tustonic tomislavtustonic at outlook.com
Sat Jul 26 22:27:53 UTC 2014


Hello

Is it possible to run a Pony ORM query in a different thread.
In the following example the first call to 'printPersons' works fine, but the 
call from the thread throws an exception:
OperationalError: no such table: Person

from pony.orm import *
import threading

db = Database('sqlite', ':memory:')
class Person(db.Entity):
    name = Required(unicode)
    age = Required(int)
db.generate_mapping(create_tables=True)
with db_session:
    p1 = Person(name="Bing Bang", age="31")
    p2 = Person(name="Kick Mick", age="75")

def printPersons():
    print "print persons: "
    with db_session:
        ps = Person.select(lambda p: True)
        for p in ps:
            print p.name

printPersons()
print "-------------------------"
ppt = threading.Thread(target = printPersons)
ppt.daemon = True
ppt.start()
a = raw_input('[Enter]')

 Thanks in advance,
Tom
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20140727/9238310f/attachment.html>


More information about the ponyorm-list mailing list