<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><p abp="170">Great!</p><p abp="170">Thanks a lot,</p><p abp="170">Tom<br abp="171"> </p><div abp="172"><hr id="stopSpelling" abp="173">Date: Sun, 27 Jul 2014 03:18:27 +0400<br abp="174">From: alexander.kozlovsky@gmail.com<br abp="175">To: ponyorm-list@ponyorm.org<br abp="176">Subject: Re: [PonyORM-list] Running in thread ?<br abp="177"><br abp="178">Hi Tom!<div abp="179"><br abp="180"></div><div abp="181">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.</div>
<div abp="182"><br abp="183"></div><div abp="184">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.</div><div abp="185"><br abp="186"></div>
<div abp="187">Regards,</div><div abp="188">Alexander</div><div abp="189"><br abp="190"><br abp="191">On Sunday, July 27, 2014, Tomislav Tustonic <<a href="mailto:tomislavtustonic@outlook.com" abp="192">tomislavtustonic@outlook.com</a>> wrote:<br abp="193"><blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" abp="194">
<div abp="195"><div dir="ltr" abp="196"><p abp="197">Hello
<br abp="198">
<br abp="199">Is it possible to run a Pony ORM query in a different thread.
<br abp="200">In the following example the first call to 'printPersons' works fine, but the
call from the thread throws an exception:
<br abp="201">OperationalError: no such table: Person
<br abp="202">
</p><p abp="203"><br abp="204">from pony.orm import *
<br abp="205">import threading
<br abp="206">
<br abp="207">db = Database('sqlite', ':memory:')
<br abp="208">class Person(db.Entity):
<br abp="209"> name = Required(unicode)
<br abp="210"> age = Required(int)
<br abp="211">db.generate_mapping(create_tables=True)
<br abp="212">with db_session:
<br abp="213"> p1 = Person(name="Bing Bang", age="31")
<br abp="214"> p2 = Person(name="Kick Mick", age="75")
<br abp="215">
<br abp="216">def printPersons():
<br abp="217"> print "print persons: "
<br abp="218"> with db_session:
<br abp="219"> ps = Person.select(lambda p: True)
<br abp="220"> for p in ps:
<br abp="221"> print <a href="http://p.name" target="_blank" abp="222">p.name</a>
<br abp="223">
<br abp="224">printPersons()
<br abp="225">print "-------------------------"
<br abp="226">ppt = threading.Thread(target = printPersons)
<br abp="227">ppt.daemon = True
<br abp="228">ppt.start()
<br abp="229">a = raw_input('[Enter]')
<br abp="230">
</p><p abp="231"> </p><p abp="232"><br abp="233">Thanks in advance,
<br abp="234">Tom
</p> </div></div>
</blockquote></div>
<br abp="235">_______________________________________________
ponyorm-list mailing list
ponyorm-list@ponyorm.org
/ponyorm-list</div> </div></body>
</html>