<div dir="ltr"><div><div><div><div><div>Hi Arthur!<br><br></div>Now I get your problem.<br><br></div>The `disconnect` method does not reverse what `bind` and `generate_mapping` methods do. Once the Database object is binded to specific physical database, it cannot be unbinded. But you can create new database object instead of the previous one. Also, it is possible to have several database objects at once.<br><br></div>To solve your problem, just place the next line at the top of your `Connect` method:<br><br></div>    theDB.db = Database()<br><br></div>This way you will create new db object each time you call `Create` method.<br><br><div><div><div><div>The `disconnect` method is just optimization which allows the program to drop connection to previous database server and to garbage-collect previous db object.<br></div><div><br></div><div>By the way, it is not necessary to have `theDB` class inside of your `theDB` module. In Python, each module is already a Singleton instance.Because of this, you can just place `db = Database()` right into your `theDB` module itself. Then your need to replace `from theDB import *` to `import theDB` in all of your modules, and all should work as before.<br></div><div><br><div class="gmail_extra"><br>Regards,<br></div><div class="gmail_extra">A.K.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 11, 2014 at 5:54 PM, Goldberg, Arthur P <span dir="ltr"><<a href="mailto:arthur.p.goldberg@mssm.edu" target="_blank">arthur.p.goldberg@mssm.edu</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div>
<div style="word-wrap:break-word">Hi Alexander
<div><br>
</div>
<div>Thanks! Yes, your simple program works.</div>
<div>As far as I know, I'm using 1 thread, and I'd like to switch between different dbmses. </div>
<div>Basically, I'm using</div>
<div>bind()</div>
<div>generate_mapping()</div>
<div>disconnect()</div>
<div>
<div>bind()</div>
</div>
<div><br>
</div>
<div>and getting </div>
<div>
<div>TypeError: Database object was already bound to MySQL provider</div>
</div>
<div>on the 2nd bind().</div>
<div><br>
</div>
<div>Here's a bit of my code.</div>
<div>test program t.py</div>
<div>the connection manager, geneticsDBMScommon.py</div>
<div>a shared singleton database handle, theDB.py</div>
<div>geneticsSubjects and geneticsClasses just define classes.<br>
<br>
</div>
<div>I can simplify the example if you like.</div>
<div><br>
</div>
<div>A</div>
<div><br>
</div>
<div></div>
</div>
<div style="word-wrap:break-word">
<div></div>
</div>
<div style="word-wrap:break-word">
<div></div>
<div></div>
</div>
<div style="word-wrap:break-word">
<div></div>
<div><br>
</div>
<div><br>
<div><div><div class="h5">
<div>On Dec 10, 2014, at 6:06 PM, Alexander Kozlovsky <<a href="mailto:alexander.kozlovsky@gmail.com" target="_blank">alexander.kozlovsky@gmail.com</a>> wrote:</div>
<br>
</div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr">
<div>
<div>Hi Arthur!<br>
<br>
</div>
<div>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:<br>
</div>
<div><br>
</div>
    from pony.orm import *<br>
<br>
    db = Database('mysql', host="myhost", user="me", passwd="123", db="mydb")<br>
<br>
    class Person(db.Entity):<br>
        name = Required(str)<br>
<br>
    db.generate_mapping(create_tables=True)<br>
<br>
    with db_session:<br>
        p1 = Person(name='John')<br>
<br>
    db.disconnect()<br>
<br>
</div>
<br>
The disconnect method works for current thread only. It releases connection to the server which db object holds in its connection pool.<br>
<div><br>
</div>
<div>This method should be called outside of any db session.<br>
</div>
<div><br>
</div>
<div>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.<br>
</div>
<div><br>
<br>
</div>
<div>Regards,<br>
</div>
<div>Alexander Kozlovsky<br>
</div>
<div><br>
</div>
</div>
<div><br>
<div>On Wed, Dec 10, 2014 at 5:39 AM, Goldberg, Arthur P <span dir="ltr">
<<a href="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=" target="_blank">arthur.p.goldberg@mssm.edu</a>></span>
 wrote:<br>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hi Guys
<div><br>
</div>
<div>Could you please show an example with disconnect()? I'm using a couple of dbmses in one SQL server, and getting </div>
<div>
<div>Database object was already bound to MySQL provider</div>
<div>Sorry, I'm too rushed to debug carefully.</div>
<div><br>
</div>
<div>Yhanks</div>
<div>A</div>
<div><br>
</div>
<div><br>
<div>
<div style="font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<span style="border-collapse:separate;border-spacing:0px">
<div style="word-wrap:break-word"><span style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<div style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
---</div>
<div> </div>
<div>Arthur Goldberg
<div style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
Associate Professor of Psychiatry</div>
<div>Seaver Autism Center and Icahn Institute for Genomics & Multiscale Biology</div>
<div>Icahn School of Medicine at Mount Sinai</div>
<div style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
Seaver Center, Room ABE-33</div>
<div style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
212-241-4229<br>
<a href="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=" target="_blank">Arthur.Goldberg@mssm.edu</a></div>
</div>
</div>
<div>Follow us on Twitter <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__twitter.com_IcahnInstitute&d=AAMFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=MdhUTa5GEj8B5HsquznH3IF3hQvAX2z34nrPC35Fbqc&s=b8XJr7NW4WKs0NkKVXPX5Ua1nTWBMEFE6nwzM3mLer0&e=" target="_blank">@IcahnInstitute</a></div>
<div style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<br>
</div>
</div>
</div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</div>
</div>
<br>
<br>
</div>
<br>
</div>
</div>
</div>
<br>
_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="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=" target="_blank">/ponyorm-list</a><br>
<br>
</blockquote>
</div>
<br>
</div>
_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
</div></div><a href="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=" target="_blank">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=</a>
<br>
</blockquote>
</div><span class="">
<br>
<div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">
<span style="border-collapse:separate;border-spacing:0px">
<div style="word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word"><span style="text-indent:0px">
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
---</div>
<div> </div>
<div>Arthur Goldberg
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
Associate Professor of Psychiatry</div>
<div>Seaver Autism Center and Icahn Institute for Genomics & Multiscale Biology</div>
<div>Icahn School of Medicine at Mount Sinai</div>
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
Seaver Center, Room ABE-33</div>
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
212-241-4229<br>
<a href="mailto:Arthur.Goldberg@mssm.edu" target="_blank">Arthur.Goldberg@mssm.edu</a></div>
</div>
</div>
<div>Follow us on Twitter <a href="https://twitter.com/IcahnInstitute" target="_blank">@IcahnInstitute</a></div>
<div style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px;font-size:medium">
<br>
</div>
</div>
</div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</span></div>
</div>
</div>
<br>
<br>
</div>
<br>
</span></div>
</div>
</div>

<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div></div></div></div></div></div></div>