io_sql.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:netcrawl 作者: Wyko 项目源码 文件源码
def __exit__(self, ty, val, tb):
        end = time.time()

        # Ignore the problem if we just added a duplicate
        if ty is None:
            log('SQL execution in [{}] completed without error. Duration: [{:.3f}]'.format(
                self.proc, end - self.start), proc=self.proc, v=logging.D)

        # Handle duplicate entry violations    
        elif (ty is psycopg2.IntegrityError) and self.ignore_duplicates:
            if (val.pgcode in (errorcodes.UNIQUE_VIOLATION,
                               errorcodes.NOT_NULL_VIOLATION,
                )):
                log('SQL execution in [{}] completed. Null or Unique constraint hit [{}]. Duration: [{:.3f}]'.format(
                    self.proc, val.pgerror, end - self.start), proc=self.proc, v=logging.I)
                return True

        else:
            log('Finished SQL execution in [{}] after [{:.3f}] seconds with [{}] error [{}]. Traceback: [{}]'.format(
                self.proc, end - self.start, ty.__name__, str(val), traceback.format_tb(tb)),
                proc=self.proc, v=logging.I)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号