I am doing web development using Cherrypy
in Python.
I had a working web page that did not have errors, but after I started using Mako
for the front-end codes to parametrize it, the following error message pops up.
Python quit unexpectedly while using the libmysqlclient.18.dylib plug-in.
also it's throwing the following error at the console.
127.0.0.1 - - [09/Apr/2014:11:20:00] "GET /submit_data?idx=2 HTTP/1.1" 200 5990 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36"
python(375,0x103980000) malloc: *** error for object 0x7fb5a4061000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
It seems like an error from C compiler, and maybe due to MySQL, but I cannot figure out what is wrong.
What can I do? I am guessing maybe I am using MySQL in a wrong way, I am attaching the Python code snippet in which I make connections to MySQL databases and use it.
dbdict = {}
for name in params["dashboards"]:
for chart in params["dashboards"][name]:
dbdict[chart["dbname"]] = None
def connect(thread_index):
for name in dbdict:
db = params["db"][name]
dbdict[name] = MySQLdb.connect(db["host"], db["user"], db["password"], db["dbname"])
cherrypy.engine.subscribe('start_thread', connect)
class AjaxApp(object):
@cherrypy.expose
@cherrypy.tools.mako(filename="index.html", directories=MEDIA_DIR)
def index(name=None):
return {'size': len(params["dashboards"]["first"])}
@cherrypy.expose
def submit_data(self, idx):
idx = int(idx)
chart = params["dashboards"]["first"][idx]
# Sample page that displays the number of records in "table"
# Open a cursor, using the DB connection for the current thread
c = dbdict[chart["dbname"]].cursor()
print 'query being executed......'
c.execute(chart["command"])
print 'query being fetched......'
res = c.fetchall()
c.close()
# construct a JSON object from query result
jsres = []
jsres.append(chart["selected"])
q_result = []
for x in res:
tmp_arr = []
for i in x:
if type(i) is datetime.datetime:
tmp_arr.append(str(i))
else:
tmp_arr.append(i)
q_result.append(tmp_arr)
jsres.append(q_result)
return json.dumps(jsres)
Here I am connecting to all dbs that are used, and putting them in a python dictionary, and whenever I am running a query command, I look up the corresponding db object, and make queries using it.
Now my connect
function looks like this
def connect(thread_index):
for name in dbdict:
print name
db = params["db"][name]
cherrypy.thread_data.db = MySQLdb.connect(db["host"], db["user"], db["password"], db["dbname"])
dbdict[name] = cherrypy.thread_data.db
I am having the same error.