Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "mysql server has gone away" in mysql cache backend #34

Closed
lorien opened this issue Dec 13, 2013 · 4 comments
Closed

Fix "mysql server has gone away" in mysql cache backend #34

lorien opened this issue Dec 13, 2013 · 4 comments

Comments

@lorien
Copy link
Owner

lorien commented Dec 13, 2013

How to repeat:

  1. Start spider, use mysql cache
  2. Pause spider execution (for instance, import pdb; pdb.set_trace()) in some task handler
  3. Wait for a some time, well, 5 hours, for example :)
  4. Get the error: mysql has gone away
@asakasinsky
Copy link
Contributor

Hi, @lorien
There are my db.py, SQLAlchemy template for all my projects. Parsers, Flask sites etc.
«mysql has gone away» is solved.

I drop this file into some project, example:
..
./models/
./app.py
./db.py

and init db in app:

from db import db_session, init_db
SQLALCHEMY_DATABASE_URI = "mysql+mysqldb://%s:%s@%s/%s?charset=utf8" % (db_user, db_pass, db_host, db_name)
init_db(SQLALCHEMY_DATABASE_URI)
...
...
db_session.add(Model)
db_session.commit()

And Model:

from sqlalchemy import (
    Column,
    Integer,
)
from db import Base

class User(Base):
    """User Model"""
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)

@asakasinsky
Copy link
Contributor

«Patch» action log:
2014-10-13 17:47:30,027 INFO sqlalchemy.pool.QueuePool Connection <_mysql.connection open to '127.0.0.1' at 7ffcb48eca20> exceeded timeout; recycling
2014-10-14 21:02:31,507 INFO sqlalchemy.pool.QueuePool Connection <_mysql.connection open to '127.0.0.1' at 7ffcb4002220> exceeded timeout; recycling

@lorien
Copy link
Owner Author

lorien commented May 2, 2015

Пожалуй, закрою этот тикет, так как я его сам открывал, а фунциональность эта мне уже сто лет как не нужна.

@lorien lorien closed this as completed May 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants