[sqlalchemy] How to make sure all connections are closed?
Hi all, I've a Django app, structure of which looks something like http://codepad.org/Tha7ySNL . This app is serving few hundred customers and lately network admin said he's been seeing lot of open connections. What can I do to make sure there are no open connections? Is there anything that can guarantee there are no more open connections? All help will be really appreciated. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/PflV-kxCJCcJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Idempotence of adding an event listener
Thanks for your thorough reply Michael. The current implementation is perfectly adequate and should definitely not be made more complex to handle corner cases (the class / instance listeners precedence issue had also come to mind). Well designed code won't need to depend on the libraries it uses to handle cases like these of adding the same listener more than once. Thanks again! --Pedro. On Tuesday, July 17, 2012 3:31:42 PM UTC+1, Michael Bayer wrote: Ideally it would be once, though there are implementational complexities to this.The function that is ultimately added to the list of listeners is not always the one that you passed - in the case of mapper and attribute events, the given function is more often than not wrapped in an adapting wrapper before being passed to event registration.So at the very least, OrderedSet wouldn't work here, it would need to be an ordered dictionary where at least the given function acts as the key. But ordered dictionary with listener function as key is probably not enough. If the same event function were registered more than once with different modifying arguments, that suggests the function should in fact be registered more than once, as it will behave differently with different modifying arguments passed. There's also the question of scopes, if an event function were registered onto a class, as well as onto a particular instance of that class, which one would prevail here, the per-class listener or the per-instance listener ? Say we have the per-class listener result in the removal of the per-instance listener; later, we implement removal of event. What happens when the per-class event is removed? should the per-instance listener come online again ? This would suggest we aren't using sets or dicts at all, instead it suggests some system of cascades where all the listeners remain in place but we have some rule-based system of favoring certain listeners. It seems that keeping the system simple and free of more complex promises like 'idempotence' allows us to avoid some thorny situations for now. I gave jQuery a try, which is kind of the most widely used event system, it does not appear to have idempotent behavior either. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/7SOtaPOpSa0J. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] unicode in where clause on mysql
Hi there, I am trying to do a select on a table, where a user has a /username/ with a German umlaut like kölbel. The table in the mysql-database is utf-8. I also failed when the table was latin1. My problem is that by no(!) chance I manage to match the user and get a row from the select statement. (see version2) Should it be possible at all or am I just screwing up with my non-existent unicode-skills! ;-) Thanks a lot and kind regards Cornelius # -*- coding: utf-8 -*- from sqlalchemy import create_engine from sqlalchemy import MetaData from sqlalchemy.orm import sessionmaker from sqlalchemy import Table CONNECT_STRING=mysql://my_connect_string TABLE = linotp_user USER = ukölbel engine = create_engine(CONNECT_STRING, echo=False) meta= MetaData() Session = sessionmaker(bind=engine) session = Session() table = Table(TABLE, meta, autoload=True, autoload_with=engine) print type of user: , type(USER) select = table.select(uusername = '%s' % USER) print select statement: , select print type of select: , type(select) print Printing rows, version 1 rows = session.execute(select) for row in rows: print ::: , row print Printing rows, version 2 sel_string=uselect * from %s where username = '%s' % (TABLE, USER) print type(sel_string) print sel_string rows = engine.execute(sel_string) for row in rows: print ::: , row session.close() signature.asc Description: OpenPGP digital signature
[sqlalchemy] Hybrid comparator vs expression
If I'm writing a comparator decorator, does it take care of expression decorator too? Eg: @hybrid_property def phone_number(self): return self._phone_number @phone_number.comparator def phone_number(cls): Truncate the RHS value if it's too long to fit into the column return TruncatingComparator(cls._phone_number) @phone_number.expression ??? -- Fayaz Yusuf Khan Cloud architect, Dexetra SS, India fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com +91-9746-830-823 -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] How to make sure all connections are closed?
some of that code looks a little weird, you've got runs a statement and returns one result, but it appears to return the whole result set from execute() - but then you call close() on it, which means you won't be able to get any rows from it. so I'm guessing that's not the actual code. the specifics of how you deal with these result sets, which you're getting via a method SQLA calls connectionless, implicit execution, would determine if connections are staying open too long or not. If you get a result from execute(), then fetch a few rows from it, then forget about it, the connection for that result is still checked out from the pool and reserved for that result for any amount of time, until the result object is garbage collected. So you want to make sure the result objects get closed out in all cases, which usually means calling fetchall() on them or otherwise getting all results unconditionally. then you might want to reduce that number of connections down, 20 is quite high, and if you dont want connections to be open at all when the pool is dormant, use NullPool. More details at http://docs.sqlalchemy.org/en/rel_0_7/core/pooling.html . On Jul 18, 2012, at 3:07 AM, Oltmans wrote: Hi all, I've a Django app, structure of which looks something like http://codepad.org/Tha7ySNL . This app is serving few hundred customers and lately network admin said he's been seeing lot of open connections. What can I do to make sure there are no open connections? Is there anything that can guarantee there are no more open connections? All help will be really appreciated. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/PflV-kxCJCcJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] unicode in where clause on mysql
easiest way here would be to specify use_unicode=1charset=utf8 with the MySQL connection string, so that your MySQLdb DBAPI handles incoming unicode objects correctly. http://docs.sqlalchemy.org/en/rel_0_7/dialects/mysql.html#unicode On Jul 18, 2012, at 7:45 AM, Cornelius Kölbel wrote: Hi there, I am trying to do a select on a table, where a user has a /username/ with a German umlaut like kölbel. The table in the mysql-database is utf-8. I also failed when the table was latin1. My problem is that by no(!) chance I manage to match the user and get a row from the select statement. (see version2) Should it be possible at all or am I just screwing up with my non-existent unicode-skills! ;-) Thanks a lot and kind regards Cornelius # -*- coding: utf-8 -*- from sqlalchemy import create_engine from sqlalchemy import MetaData from sqlalchemy.orm import sessionmaker from sqlalchemy import Table CONNECT_STRING=mysql://my_connect_string TABLE = linotp_user USER = ukölbel engine = create_engine(CONNECT_STRING, echo=False) meta= MetaData() Session = sessionmaker(bind=engine) session = Session() table = Table(TABLE, meta, autoload=True, autoload_with=engine) print type of user: , type(USER) select = table.select(uusername = '%s' % USER) print select statement: , select print type of select: , type(select) print Printing rows, version 1 rows = session.execute(select) for row in rows: print ::: , row print Printing rows, version 2 sel_string=uselect * from %s where username = '%s' % (TABLE, USER) print type(sel_string) print sel_string rows = engine.execute(sel_string) for row in rows: print ::: , row session.close() PGP.sig Description: This is a digitally signed message part