On 6/13/15 3:54 AM, Dr. wrote:
I have a very simple table and query. For some reason it hangs after a
few executions and I have to restart the application.
Code to set it up:
|
fromsqlalchemy import(
Column,
Integer,
String
)
fromsqlalchemy.ext.declarative importdeclarative_base
Base=declarative_base()
classUser(Base):
__tablename__ ='users'
id =Column(Integer,primary_key=True)
pname =Column(String)
fromsqlalchemy importcreate_engine
engine
=create_engine('mysql+mysqlconnector://user:pass@server/database',echo=True)
Base.metadata.bind =engine
fromsqlalchemy.orm importsessionmaker
Session=sessionmaker(bind=engine)
session =Session()
|
The query I run is simply
|
session.query(User).all()
|
System:
* Python 3.4.3
* The database is a remote MySQL Ver 5.5.41-0ubuntu0.14.04.1 running
on debian-linux-gnu on x86_64
* MySQL Connector/Python 2.0.3
* SQLAlchemy package: SQLAlchemy-1.0.5-py3.4.egg-info (I had the
same problem with a ver < 1.0 so I upgraded but no improvement)
* The clients are local, whether run on PC or Mac the problem is the
same
Some observations:
* After I run the query a few times, the program hangs.
in what context? running the whole program from a command line each
time? Running the query inside of a loop inside of one program ?
what's important here is how are connection resources being allocated
and freed?
* If I uncomment the pname field, however, it seems like it will
never hang.
* If I replace .all() with .first() the program won't hang
* The general log on the MySQL server shows that the server receives
the query so the problem is likely on the receiving end of SQLAlchemy
* The server runs a Wordpress too which continues to function even
if the SQLAlchemy connection hangs
* echo True or False makes no difference
did you try a different driver like pymysql (much more popular Py3k
driver) ? Also what happens if you use a raw DBAPI program (e.g. with
mysqlconnector or pymysql ?) try looking at the database (e.g.
https://dev.mysql.com/doc/refman/5.0/en/show-engine.html) ?
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.