Re: [sqlalchemy] Session remove/close MySQL

2014-02-12 Thread Christian Démolis
Thx all

NullPool solve my problem
create_engine(cnx_str, poolclass=NullPool)


2014-02-07 19:11 GMT+01:00 Claudio Freire klaussfre...@gmail.com:

 On Fri, Feb 7, 2014 at 2:35 PM, Michael Bayer mike...@zzzcomputing.com
 wrote:
  The connection pool, if in use, will then not
  actually close the connection if it is to remained pooled, it calls
  rollback() as part of the pool release mechanism.  Recent versions of
  SQLAlchemy allow this to show up in the engine logs like any other
 rollback,
  so you probably wouldn't have noticed.
 
  And *this* is what was not happening. Somehow, transactions remained
  open on the database (I checked).
 
  that kind of thing generally happens to people when they aren't cleaning
 up their sessions, or are using awkward engine/connection patterns.   the
 pool has had a lot of bugs fixed but I haven't seen a bug where the pool
 isn't emitting the rollback when the connection is marked closed.

 There was an awkward pattern involved: using the session's connection
 as returned by Session.connection() manually to issue some textual
 SQL. Other than that, normal thread-local session stuff.

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] Session remove/close MySQL

2014-02-07 Thread Simon King
On Fri, Feb 7, 2014 at 9:28 AM, Christian Démolis 
christiandemo...@gmail.com wrote:

 Hi all,

 Actually, i have some problem closing my session...
 I tried using scopedsession with session.remove
 I tried using normal session with session.close

 But in both cases, the Mysql session stay open.


 Why closing session has no effet on current Mysql connections ?


SQLAlchemy maintains a pool of connections to the database. When you start
a session, it checks a connection out from the pool, and when you close the
session, it returns it to the pool. There are various configuration
parameters you can use to control how the pool works. See the docs at
http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html

Hope that helps,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] Session remove/close MySQL

2014-02-07 Thread Michael Bayer

On Feb 7, 2014, at 11:01 AM, Claudio Freire klaussfre...@gmail.com wrote:

 
 I've had similar issues with 0.7.10. SA opens an implicit transaction,

incorrect, DBAPI does this, please see: 
http://www.python.org/dev/peps/pep-0249/#commit

there is no “explicit transaction” in DBAPI.   The docs have tried very hard to 
emphasize this as it is misleading to new users, but its outside of SQLAlchemy.

 and neither Session.remove nor Session.close really roll back the transaction

session.rollback() rolls back the transaction.   if you don’t call that, 
session.close() is as though you just closed the connection and did nothing, 
IMHO as it should be.  The connection pool, if in use, will then not actually 
“close” the connection if it is to remained pooled, it calls rollback() as part 
of the pool release mechanism.  Recent versions of SQLAlchemy allow this to 
show up in the engine logs like any other rollback, so you probably wouldn’t 
have noticed.

 (even though they should, I've had lots of experimental evidence that it does 
 not always do it).
 
 So, what I suggest, is issuing a session.commit() or session.rollback() 
 (according to your transactional needs) before the session.close/remove
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/groups/opt_out.



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [sqlalchemy] Session remove/close MySQL

2014-02-07 Thread Claudio Freire
I knew I should've been more explicit

On Fri, Feb 7, 2014 at 1:07 PM, Michael Bayer mike...@zzzcomputing.com wrote:
 On Feb 7, 2014, at 11:01 AM, Claudio Freire klaussfre...@gmail.com wrote:


 I've had similar issues with 0.7.10. SA opens an implicit transaction,


 incorrect, DBAPI does this, please see:
 http://www.python.org/dev/peps/pep-0249/#commit

Ok, yeah. The point is, it's open.


 and neither Session.remove nor Session.close really roll back the
 transaction

No, but the connection pool should. (reset_on_return, which I have enabled)

 The connection pool, if in use, will then not
 actually close the connection if it is to remained pooled, it calls
 rollback() as part of the pool release mechanism.  Recent versions of
 SQLAlchemy allow this to show up in the engine logs like any other rollback,
 so you probably wouldn't have noticed.

And *this* is what was not happening. Somehow, transactions remained
open on the database (I checked).

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] Session remove/close MySQL

2014-02-07 Thread Claudio Freire
On Fri, Feb 7, 2014 at 2:35 PM, Michael Bayer mike...@zzzcomputing.com wrote:
 The connection pool, if in use, will then not
 actually close the connection if it is to remained pooled, it calls
 rollback() as part of the pool release mechanism.  Recent versions of
 SQLAlchemy allow this to show up in the engine logs like any other rollback,
 so you probably wouldn't have noticed.

 And *this* is what was not happening. Somehow, transactions remained
 open on the database (I checked).

 that kind of thing generally happens to people when they aren't cleaning up 
 their sessions, or are using awkward engine/connection patterns.   the pool 
 has had a lot of bugs fixed but I haven't seen a bug where the pool isn't 
 emitting the rollback when the connection is marked closed.

There was an awkward pattern involved: using the session's connection
as returned by Session.connection() manually to issue some textual
SQL. Other than that, normal thread-local session stuff.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] Session remove/close MySQL

2014-02-07 Thread Michael Bayer

On Feb 7, 2014, at 11:16 AM, Claudio Freire klaussfre...@gmail.com wrote:

 and neither Session.remove nor Session.close really roll back the
 transaction
 
 No, but the connection pool should. (reset_on_return, which I have enabled)

reset_on_return is on by default.  the pool has always emitted a rollback, the 
reset_on_return feature was added for some folks who either wanted to do 
nothing for MySQL/MyISAM, or wanted it to do a commit() on SQL Server.

 
 The connection pool, if in use, will then not
 actually close the connection if it is to remained pooled, it calls
 rollback() as part of the pool release mechanism.  Recent versions of
 SQLAlchemy allow this to show up in the engine logs like any other rollback,
 so you probably wouldn't have noticed.
 
 And *this* is what was not happening. Somehow, transactions remained
 open on the database (I checked).

that kind of thing generally happens to people when they aren’t cleaning up 
their sessions, or are using awkward engine/connection patterns.   the pool has 
had a lot of bugs fixed but I haven’t seen a bug where the pool isn’t emitting 
the rollback when the connection is marked closed.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [sqlalchemy] Session remove/close MySQL

2014-02-07 Thread Claudio Freire
On Fri, Feb 7, 2014 at 11:51 AM, Simon King si...@simonking.org.uk wrote:

 On Fri, Feb 7, 2014 at 9:28 AM, Christian Démolis 
 christiandemo...@gmail.com wrote:

 Hi all,

 Actually, i have some problem closing my session...
 I tried using scopedsession with session.remove
 I tried using normal session with session.close

 But in both cases, the Mysql session stay open.


 Why closing session has no effet on current Mysql connections ?


 SQLAlchemy maintains a pool of connections to the database. When you start
 a session, it checks a connection out from the pool, and when you close the
 session, it returns it to the pool. There are various configuration
 parameters you can use to control how the pool works. See the docs at
 http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html



I've had similar issues with 0.7.10. SA opens an implicit transaction, and
neither Session.remove nor Session.close really roll back the transaction
(even though they should, I've had lots of experimental evidence that it
does not always do it).

So, what I suggest, is issuing a session.commit() or session.rollback()
(according to your transactional needs) before the session.close/remove

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.