专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Perl/Python

python链接psql数据库操作诗诡异的异常

发布时间:2011-06-29 20:11:28 文章来源:www.iduyao.cn 采编人员:星星草
python链接psql数据库操作诗诡异的错误
我写了个脚本,碰到了个诡异的问题,请大家帮忙看看。

先看下我封装的sql执行函数,参数分别为:pgdb的connecter,需要执行的sql语句,执行时间,文件指针
这个函数大致意思是先执行一句sql,然后把这句sql执行时的一些信息记录到dubug这张表中

def sql_commit(db,sql_comment,cal_date,filepoint):
  cursor = db.cursor()
  sql_start_time = datetime.datetime.now()
  try:
cursor.execute(sql_comment)
db.commit()
filepoint.write(sql_comment)
filepoint.write('\n')
num = cursor.rowcount
sql_end_time = datetime.datetime.now()
  sql_run_time = (sql_end_time - sql_start_time).microseconds
  sql_des = sql_comment.replace('\'','')
  sql_comment = """insert into dpods.debug values('mid_coupon_sd.py','%s','%s','%s','%s','%s','%s')"""%(sql_des,sql_start_time,sql_end_time,num,sql_run_time,cal_date)
cursor.execute(sql_comment)
filepoint.write(sql_comment)
filepoint.write('\n')
db.commit()
cursor.close()
return num
  except Exception, e:
  cursor.close()
time = datetime.datetime.now()
errornow = time.strftime("%Y-%m-%d %H:%M:%S") 
filepoint.write('end fail[')
filepoint.write(errornow)
filepoint.write(']\n')
error = repr(e)
filepoint.write(error)
filepoint.write('\n\n')
print 'end fail[%s]'%time
print e
return -2

然后发现在执行到某一句sql的时候报错,OperationalError("can't commit",)
具体错误如下:
WARNING: The distributed transaction 'Abort [Prepared]' broadcast failed to one or more segments for gid = 1323529276-0000367848.
NOTICE: Releasing gangs for retry broadcast.
NOTICE: Retry of the distributed transaction 'Abort Prepared' broadcast succeeded to the segments for gid = 1323529276-0000367848.
end fail[2011-12-28 09:56:33.040006]

但是这个错误是有的时候发生!有的时候不发生!大家帮忙分析下什么问题,或者可能是什么问题引起的错误,多谢多谢


------解决方案--------------------
这个看过了没?
http://space.itpub.net/25548387/viewspace-703160
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: