当前位置: 首页>>代码示例>>Python>>正文


Python Session.rollback方法代码示例

本文整理汇总了Python中scatterbrainz.model.meta.Session.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python Session.rollback方法的具体用法?Python Session.rollback怎么用?Python Session.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scatterbrainz.model.meta.Session的用法示例。


在下文中一共展示了Session.rollback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from scatterbrainz.model.meta import Session [as 别名]
# 或者: from scatterbrainz.model.meta.Session import rollback [as 别名]
 def run(self):
     
     # Only let one worker run via pg advisory lock
     acquired = Session.execute(select([func.pg_try_advisory_lock(importlockid)])).fetchone()[0]
     threadid = 'PID ' + str(os.getpid()) + ' thread ' + str(threading.current_thread())
     if acquired:
         log.info('[shop worker] %s acquired lock, starting..' % threadid)
     else:
         return
     
     pendingdownloads = False
     while True:
         try:
             downloads = Session.query(ShopDownload) \
                                .filter(ShopDownload.isdone==False) \
                                .filter(ShopDownload.failedimport==False) \
                                .all()
             pendingdownloads = len(downloads) != 0
             if pendingdownloads:
                 rtorrent = xmlrpclib.ServerProxy(Config.SHOP_RPC_URL)
                 for download in downloads:
                     try:
                         infohash = download.infohash
                         iscomplete = rtorrent.d.get_complete(infohash) == 1
                         if iscomplete:
                             shopservice.importDownload(download)
                     except:
                         exc_type, exc_value, exc_traceback = sys.exc_info()
                         importtrace = repr(traceback.format_exception(exc_type, exc_value, exc_traceback))
                         log.error('[shop worker] caught exception in loop ' + importtrace)
                         Session.rollback()
                         Session.begin()
                         download.failedimport = True
                         download.importtrace = importtrace
                         Session.commit()
         except Exception as e:
             log.error('[shop worker] caught exception out of loop ' + repr(e))
             Session.rollback()
         if pendingdownloads:
             time.sleep(10)
         else:
             time.sleep(30)
开发者ID:GunioRobot,项目名称:scatterbrainz,代码行数:44,代码来源:shopworker.py


注:本文中的scatterbrainz.model.meta.Session.rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。