同時に多くの接続を処理できる/できるはずのサーバーがあります。「クエリ中に MySQL サーバーへの接続が失われました」というエラーが表示されることがあります。現時点では、これを修正しています
def mysql_handling(string):
global cursor
tries=0
while True:
if tries<5:
try:
cursor.execute(string)
if 'SELECT' not in string:
db.commit()
break
except MySQLdb.Error, e:
print("Error %d: %s" %(e.args[0], e.args[1]))
cursor.close()
time.sleep(0.1)
cursor = get_cursor() #setting up a new mysql connection
#mysql_error_tracking(string)
tries+=1
else:
sys.exit(1)
これで、同時に多くの接続を処理できるようになりましたが、このエラー (Lost conn.) が発生したときに、これがどのクエリで発生したか、およびこれに何らかのパターンがあるかどうかを知りたいです。したがって、これを追跡するために、次のようなスクリプトを使用してこれを mysql-database に保存することも必要です。
def mysql_error_tracking(string):
#Clone/fork
try:
error_serv = os.fork()
except:
print "error_FORK failed!"
if error_serv:
print 'there is a MYSQL-ERROR, SAVE!!!'
cursor.execute("SELECT count FROM query_errors WHERE string= "+"'"+str(string)+"'")
data=cursor.fetchone()
print data
if data is None:
cursor.execute("INSERT INTO query_errors (string) VALUES ("+"'"+str(string)+"')")
db.commit()
print 'insert in queries'
else:
cursor.execute("UPDATE query_errors SET count=count+1 WHERE string= "+"'"+str(string)+"'")
db.commit()
print 'count ploes 1'
sys.exit(0)
これは機能しますが、接続をフォークすると、既存の mysql 接続が実際に圧迫されるようです。代わりに、フォークしない方が良いですか?