[PonyORM-list] Running in thread ?

Tomislav Tustonic tomislavtustonic at outlook.com
Sat Jul 26 23:50:46 UTC 2014


Great!Thanks a lot,Tom Date: Sun, 27 Jul 2014 03:18:27 +0400From: alexander.kozlovsky at gmail.comTo: ponyorm-list at ponyorm.comSubject: Re: [PonyORM-list] Running in thread ?Hi Tom!Yes, Pony ORM can be used from multiple thread, if (as in your example), each thread uses its own db session. But SQLite in-memory database can have only one connection. Because of this, SQLite in-memory database cannot be used from multiple threads. Try to specify database file name, and all should works as expected.
I think that Pony ORM should check if somebody tries to access SQLite in-memory database from multiple threads, and generate appropriate error message. I'll fix it in next release.
Regards,AlexanderOn Sunday, July 27, 2014, Tomislav Tustonic <tomislavtustonic at outlook.com> wrote:



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
 		 	   		  

_______________________________________________
ponyorm-list mailing list
ponyorm-list at ponyorm.com
/ponyorm-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20140727/683542fb/attachment.html>


More information about the ponyorm-list mailing list