[PonyORM-list] Example with disconnect()
Goldberg, Arthur P
arthur.p.goldberg at mssm.edu
Thu Dec 11 14:54:04 UTC 2014
Hi Alexander
Thanks! Yes, your simple program works.
As far as I know, I'm using 1 thread, and I'd like to switch between different dbmses.
Basically, I'm using
bind()
generate_mapping()
disconnect()
bind()
and getting
TypeError: Database object was already bound to MySQL provider
on the 2nd bind().
Here's a bit of my code.
test program t.py
the connection manager, geneticsDBMScommon.py
a shared singleton database handle, theDB.py
geneticsSubjects and geneticsClasses just define classes.
I can simplify the example if you like.
A
On Dec 10, 2014, at 6:06 PM, Alexander Kozlovsky <alexander.kozlovsky at gmail.com<mailto:alexander.kozlovsky at gmail.com>> wrote:
Hi Arthur!
For what purpose do you want to use `disconnect` method? I'm not sure I correctly understand what example you want to see, but the simplest example of `disconnect` method is this:
from pony.orm import *
db = Database('mysql', host="myhost", user="me", passwd="123", db="mydb")
class Person(db.Entity):
name = Required(str)
db.generate_mapping(create_tables=True)
with db_session:
p1 = Person(name='John')
db.disconnect()
The disconnect method works for current thread only. It releases connection to the server which db object holds in its connection pool.
This method should be called outside of any db session.
If you application is multi-threaded and you want to disconnect your db object from the database, the you need to call `disconnect` method from each thread in which you have worked with the entities of this db object.
Regards,
Alexander Kozlovsky
On Wed, Dec 10, 2014 at 5:39 AM, Goldberg, Arthur P <arthur.p.goldberg at mssm.edu<https://urldefense.proofpoint.com/v2/url?u=http-3A__mailto-3Aarthur.p.goldberg-40mssm.edu&d=AAMFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=MdhUTa5GEj8B5HsquznH3IF3hQvAX2z34nrPC35Fbqc&s=ct-V7Z7acRopVeskia8UT4P3-cU9cGjInrFDZss0TLk&e=>> wrote:
Hi Guys
Could you please show an example with disconnect()? I'm using a couple of dbmses in one SQL server, and getting
Database object was already bound to MySQL provider
Sorry, I'm too rushed to debug carefully.
Yhanks
A
---
Arthur Goldberg
Associate Professor of Psychiatry
Seaver Autism Center and Icahn Institute for Genomics & Multiscale Biology
Icahn School of Medicine at Mount Sinai
Seaver Center, Room ABE-33
212-241-4229
Arthur.Goldberg at mssm.edu<https://urldefense.proofpoint.com/v2/url?u=http-3A__mailto-3AArthur.Goldberg-40mssm.edu&d=AAMFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=MdhUTa5GEj8B5HsquznH3IF3hQvAX2z34nrPC35Fbqc&s=zyJFM3R79vy0YD4o6VWXoHEs0OQXaiwdQ3nrXfBIBN8&e=>
Follow us on Twitter @IcahnInstitute<https://urldefense.proofpoint.com/v2/url?u=https-3A__twitter.com_IcahnInstitute&d=AAMFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=MdhUTa5GEj8B5HsquznH3IF3hQvAX2z34nrPC35Fbqc&s=b8XJr7NW4WKs0NkKVXPX5Ua1nTWBMEFE6nwzM3mLer0&e=>
_______________________________________________
ponyorm-list mailing list
ponyorm-list at ponyorm.com<mailto:ponyorm-list at ponyorm.com>
/ponyorm-list<https://urldefense.proofpoint.com/v2/url?u=https-3A__mailman-2Dmail5.webfaction.com_listinfo_ponyorm-2Dlist&d=AAMFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=MdhUTa5GEj8B5HsquznH3IF3hQvAX2z34nrPC35Fbqc&s=EqprhF2xxCO00Y6lH7LjUW0WmnyegTuf-EW5kECRTA8&e=>
_______________________________________________
ponyorm-list mailing list
ponyorm-list at ponyorm.com<mailto:ponyorm-list at ponyorm.com>
https://urldefense.proofpoint.com/v2/url?u=https-3A__mailman-2Dmail5.webfaction.com_listinfo_ponyorm-2Dlist&d=AAIGaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=MdhUTa5GEj8B5HsquznH3IF3hQvAX2z34nrPC35Fbqc&s=EqprhF2xxCO00Y6lH7LjUW0WmnyegTuf-EW5kECRTA8&e=
---
Arthur Goldberg
Associate Professor of Psychiatry
Seaver Autism Center and Icahn Institute for Genomics & Multiscale Biology
Icahn School of Medicine at Mount Sinai
Seaver Center, Room ABE-33
212-241-4229
Arthur.Goldberg at mssm.edu<mailto:Arthur.Goldberg at mssm.edu>
Follow us on Twitter @IcahnInstitute<https://twitter.com/IcahnInstitute>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20141211/28d46bd8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.py
Type: text/x-python-script
Size: 398 bytes
Desc: t.py
URL: </ponyorm-list/attachments/20141211/28d46bd8/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: theDB.py
Type: text/x-python-script
Size: 116 bytes
Desc: theDB.py
URL: </ponyorm-list/attachments/20141211/28d46bd8/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geneticsDBMScommon.py
Type: text/x-python-script
Size: 2449 bytes
Desc: geneticsDBMScommon.py
URL: </ponyorm-list/attachments/20141211/28d46bd8/attachment-0002.bin>
More information about the ponyorm-list
mailing list