Note that there are some explanatory texts on larger screens.

plurals
  1. POGearman + SQLAlchemy - keep losing MySQL thread
    primarykey
    data
    text
    <p>I have a python script that sets up several gearman workers. They call into some methods on SQLAlchemy models I have that are also used by a Pylons app.</p> <p>Everything works fine for an hour or two, then the MySQL thread gets lost and all queries fail. I cannot figure out why the thread is getting lost (I get the same results on 3 different servers) when I am defining such a low value for pool_recycle. Also, why wouldn't a new connection be created?</p> <p>Any ideas of things to investigate?</p> <pre><code>import gearman import json import ConfigParser import sys from sqlalchemy import create_engine class JSONDataEncoder(gearman.DataEncoder): @classmethod def encode(cls, encodable_object): return json.dumps(encodable_object) @classmethod def decode(cls, decodable_string): return json.loads(decodable_string) # get the ini path and load the gearman server ips:ports try: ini_file = sys.argv[1] lib_path = sys.argv[2] except Exception: raise Exception("ini file path or anypy lib path not set") # get the config config = ConfigParser.ConfigParser() config.read(ini_file) sqlachemy_url = config.get('app:main', 'sqlalchemy.url') gearman_servers = config.get('app:main', 'gearman.mysql_servers').split(",") # add anypy include path sys.path.append(lib_path) from mypylonsapp.model.user import User, init_model from mypylonsapp.model.gearman import task_rates # sqlalchemy setup, recycle connection every hour engine = create_engine(sqlachemy_url, pool_recycle=3600) init_model(engine) # Gearman Worker Setup gm_worker = gearman.GearmanWorker(gearman_servers) gm_worker.data_encoder = JSONDataEncoder() # register the workers gm_worker.register_task('login', User.login_gearman_worker) gm_worker.register_task('rates', task_rates) # work gm_worker.work() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload