• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python g.make_lock函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pylons.g.make_lock函数的典型用法代码示例。如果您正苦于以下问题:Python make_lock函数的具体用法?Python make_lock怎么用?Python make_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: add_message

def add_message(message):
    # add the message to the author's list and the recipient
    with g.make_lock(messages_lock_key(message.author_id)):
        add_message_nolock(message.author_id, message)
    if message.to_id:
        with g.make_lock(messages_lock_key(message.to_id)):
            add_message_nolock(message.to_id, message)
    if message.sr_id:
        with g.make_lock(sr_messages_lock_key(message.sr_id)):
            add_sr_message_nolock(message.sr_id, message)
开发者ID:VincentVazzo,项目名称:reddit,代码行数:10,代码来源:comment_tree.py


示例2: add_message

def add_message(message, update_recipient=True, update_modmail=True):
    # add the message to the author's list and the recipient
    with g.make_lock("message_tree", messages_lock_key(message.author_id)):
        add_message_nolock(message.author_id, message)
    if update_recipient and message.to_id:
        with g.make_lock("message_tree", messages_lock_key(message.to_id)):
            add_message_nolock(message.to_id, message)

    if update_modmail and message.sr_id:
        with g.make_lock("modmail_tree", sr_messages_lock_key(message.sr_id)):
            add_sr_message_nolock(message.sr_id, message)
开发者ID:zz198808,项目名称:reddit,代码行数:11,代码来源:comment_tree.py


示例3: add_message

def add_message(message):
    # add the message to the author's list and the recipient
    with g.make_lock("message_tree", messages_lock_key(message.author_id)):
        add_message_nolock(message.author_id, message)
    if message.to_id:
        with g.make_lock("message_tree", messages_lock_key(message.to_id)):
            add_message_nolock(message.to_id, message)
    # Messages to a subreddit should end in its inbox. Messages
    # FROM a subreddit (currently, just ban messages) should NOT
    if message.sr_id and not message.from_sr:
        with g.make_lock("modmail_tree", sr_messages_lock_key(message.sr_id)):
            add_sr_message_nolock(message.sr_id, message)
开发者ID:cooiky,项目名称:reddit,代码行数:12,代码来源:comment_tree.py


示例4: add_message

def add_message(message, update_recipient=True, update_modmail=True, add_to_user=None):
    with g.make_lock("message_tree", messages_lock_key(message.author_id)):
        add_message_nolock(message.author_id, message)

    if update_recipient and message.to_id:
        with g.make_lock("message_tree", messages_lock_key(message.to_id)):
            add_message_nolock(message.to_id, message)

    if update_modmail and message.sr_id:
        with g.make_lock("modmail_tree", sr_messages_lock_key(message.sr_id)):
            add_sr_message_nolock(message.sr_id, message)

    if add_to_user and add_to_user._id != message.to_id:
        with g.make_lock("message_tree", messages_lock_key(add_to_user._id)):
            add_message_nolock(add_to_user._id, message)
开发者ID:RobertNorthard,项目名称:reddit,代码行数:15,代码来源:comment_tree.py


示例5: link_comments

def link_comments(link_id, _update=False):
    key = comments_key(link_id)

    r = g.permacache.get(key)

    if r and not _update:
        return r
    else:
        # This operation can take longer than most (note the inner
        # locks) better to time out request temporarily than to deal
        # with an inconsistent tree
        with g.make_lock(lock_key(link_id), timeout=180):
            r = _load_link_comments(link_id)
            # rebuild parent dict
            cids, cid_tree, depth, num_children = r
            g.permacache.set(parent_comments_key(link_id),
                             _parent_dict_from_tree(cid_tree))

            # rebuild the sorts
            for sort in ("_controversy","_date","_hot","_confidence","_score"):
                g.permacache.set(sort_comments_key(link_id, sort),
                                 _comment_sorter_from_cids(cids, sort))

            g.permacache.set(key, r)
            return r
开发者ID:JediWatchman,项目名称:reddit,代码行数:25,代码来源:comment_tree.py


示例6: record_violation

    def record_violation(self, category, seconds = None, growfast=False):
        if seconds is None:
            seconds = g.RATELIMIT*60

        key = "VDelay-%s-%s" % (category, request.ip)
        prev_violations = g.memcache.get(key)
        if prev_violations is None:
            prev_violations = dict(count=0)

        num_violations = prev_violations["count"]

        if growfast:
            multiplier = 3 ** num_violations
        else:
            multiplier = 1

        max_duration = 8 * 3600
        duration = min(seconds * multiplier, max_duration)

        expire_time = (datetime.now(g.tz) +
                       timedelta(seconds = duration))

        prev_violations["expire_time"] = expire_time
        prev_violations["duration"] = duration
        prev_violations["count"] += 1

        with g.make_lock("lock-" + key, timeout=5, verbose=False):
            existing = g.memcache.get(key)
            if existing and existing["count"] > prev_violations["count"]:
                g.log.warning("Tried to set %s to count=%d, but found existing=%d"
                             % (key, prev_violations["count"], existing["count"]))
            else:
                g.cache.set(key, prev_violations, max_duration)
开发者ID:jaycobcoleman,项目名称:reddit,代码行数:33,代码来源:validator.py


示例7: _deactivate_campaign

def _deactivate_campaign(link, campaign):
    with g.make_lock('adzerk_update', 'adzerk-' + link._fullname):
        g.log.debug('running deactivate_campaign %s' % link)
        az_flight = update_flight(link, campaign)
        az_flight.IsActive = False
        az_flight._send()
        PromotionLog.add(link, 'deactivated %s' % az_flight)
开发者ID:alienth,项目名称:reddit-plugin-adzerk,代码行数:7,代码来源:adzerkpromote.py


示例8: _incr

    def _incr(self, prop, amt = 1):
        if self._dirty:
            raise ValueError, "cannot incr dirty thing"

        #make sure we're incr'ing an _int_prop or _data_int_prop.
        if prop not in self._int_props:
            if (prop in self._data_int_props or
                self._int_prop_suffix and prop.endswith(self._int_prop_suffix)):
                #if we're incr'ing a data_prop, make sure we're loaded
                if not self._loaded:
                    self._load()
            else:
                msg = ("cannot incr non int prop %r on %r -- it's not in %r or %r" %
                       (prop, self, self._int_props, self._data_int_props))
                raise ValueError, msg

        with g.make_lock("thing_commit", 'commit_' + self._fullname):
            self._sync_latest()
            old_val = getattr(self, prop)
            if self._defaults.has_key(prop) and self._defaults[prop] == old_val:
                #potential race condition if the same property gets incr'd
                #from default at the same time
                setattr(self, prop, old_val + amt)
                self._commit(prop)
            else:
                self.__setattr__(prop, old_val + amt, False)
                #db
                if prop.startswith('_'):
                    tdb.incr_thing_prop(self._type_id, self._id, prop[1:], amt)
                else:
                    self._incr_data(self._type_id, self._id, prop, amt)

            self._cache_myself()
开发者ID:Asimov4,项目名称:dobands,代码行数:33,代码来源:thing.py


示例9: process_job

    def process_job(self, job):
        if job.run_at is not None and job.run_at > datetime.now(g.tz):
            return

        runner = globals().get('job_' + job.action)
        if not runner:
            print >>stderr, 'Unknown job action {0!r}'.format(job.action)
            return

        # If we can't acquire the lock, the job has already been claimed,
        # so we skip it.
        lock = g.make_lock('pending_job_{0}'.format(job._id))
        if not lock.try_acquire():
            return

        try:
            data = job.data or {}
            runner(**data)
        except Exception as ex:
            print >>stderr, 'Exception while running job id {0} ({1}): {2}'.format(
                job._id, job.action, ex)
        else:
            self.mark_as_completed(job)
        finally:
            lock.release()
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:25,代码来源:run_pending_jobs.py


示例10: edit_campaign

def edit_campaign(link, index, dates, bid, sr):
    sr_name = sr.name if sr else ""
    with g.make_lock(campaign_lock(link)):
        campaigns = getattr(link, "campaigns", {}).copy()
        if index in campaigns:
            trans_id = campaigns[index][CAMPAIGN.trans_id]
            prev_bid = campaigns[index][CAMPAIGN.bid]
            # store the name not the reddit
            campaigns[index] = list(dates) + [bid, sr_name, trans_id]
            PromotionWeights.reschedule(link, index,
                                        sr_name, dates[0], dates[1], bid)
            link.campaigns = {}
            link.campaigns = campaigns
            promotion_log(link, "updated campaign %s. (bid: %0.2f)" % (index, bid))
            link._commit()

            #TODO cancel any existing charges if the bid has changed
            if prev_bid != bid:
                void_campaign(link, index, c.user)

    # dual-write update to campaign Thing if it exists
    try: 
        campaign = PromoCampaign._byID(index)
        campaign.set_bid(sr_name, bid, dates[0], dates[1])
        campaign._commit()
    except NotFound:
        g.log.debug("Skipping update of non-existent PromoCampaign [link:%d, index:%d]" %
                    (link._id, index))

    author = Account._byID(link.author_id, True)
    if getattr(author, "complimentary_promos", False):
        free_campaign(link, index, c.user)
开发者ID:freekrai,项目名称:reddit,代码行数:32,代码来源:promote.py


示例11: link_comments

def link_comments(link_id, _update=False):
    key = comments_key(link_id)

    r = g.permacache.get(key)

    if r and not _update:
        return r
    else:
        # This operation can take longer than most (note the inner
        # locks) better to time out request temporarily than to deal
        # with an inconsistent tree
        with g.make_lock(lock_key(link_id), timeout=180):
            r = _load_link_comments(link_id)
            # rebuild parent dict
            cids, cid_tree, depth, num_children, num_comments = r
            r = r[:-1]  # Remove num_comments from r; we don't need to cache it.
            g.permacache.set(parent_comments_key(link_id),
                             _parent_dict_from_tree(cid_tree))

            g.permacache.set(key, r)

            # update the link's comment count and schedule it for search
            # reindexing
            link = Link._byID(link_id, data = True)
            link.num_comments = num_comments
            link._commit()
            from r2.lib.db.queries import changed
            changed(link)

        return r
开发者ID:AmbroiseKritz,项目名称:reddit,代码行数:30,代码来源:comment_tree.py


示例12: __iter__

    def __iter__(self):
        used_cache = False

        def _retrieve():
            return self._cursor().fetchall()

        names = lst = []

        names = cache.get(self._iden()) if self._read_cache else None
        if names is None and not self._write_cache:
            # it wasn't in the cache, and we're not going to
            # replace it, so just hit the db
            lst = _retrieve()
        elif names is None and self._write_cache:
            # it's not in the cache, and we have the power to
            # update it, which we should do in a lock to prevent
            # concurrent requests for the same data
            with g.make_lock("thing_query", "lock_%s" % self._iden()):
                # see if it was set while we were waiting for our
                # lock
                names = cache.get(self._iden(), allow_local = False) \
                                  if self._read_cache else None
                if names is None:
                    lst = _retrieve()
                    cache.set(self._iden(),
                              [ x._fullname for x in lst ],
                              self._cache_time)

        if names and not lst:
            # we got our list of names from the cache, so we need to
            # turn them back into Things
            lst = Thing._by_fullname(names, data = self._data, return_dict = False)

        for item in lst:
            yield item
开发者ID:Asimov4,项目名称:dobands,代码行数:35,代码来源:thing.py


示例13: new_campaign

def new_campaign(link, dates, bid, sr):
    # empty string for sr_name means target to all
    sr_name = sr.name if sr else ""
    # dual-write campaigns as data Things
    campaign = PromoCampaign._new(link, sr_name, bid, dates[0], dates[1])
    # note indx in link.campaigns is the Thing id now 
    indx = campaign._id
    with g.make_lock(campaign_lock(link)):
        # get a copy of the attr so that it'll be
        # marked as dirty on the next write.
        campaigns = getattr(link, "campaigns", {}).copy()
        # add the campaign
        campaigns[indx] = list(dates) + [bid, sr_name, 0]
        PromotionWeights.add(link, indx, sr_name, dates[0], dates[1], bid)
        link.campaigns = {}
        link.campaigns = campaigns
        promotion_log(link, "campaign %s created" % campaign._id)
        link._commit()


    author = Account._byID(link.author_id, True)
    if getattr(author, "complimentary_promos", False):
        free_campaign(link, indx, c.user)

    return indx
开发者ID:freekrai,项目名称:reddit,代码行数:25,代码来源:promote.py


示例14: _deactivate_overdelivered

def _deactivate_overdelivered(link, campaign):
    with g.make_lock('adzerk_update', 'adzerk-' + link._fullname):
        msg = '%s deactivating adzerk flight for %s - %s'
        g.log.info(msg % (datetime.datetime.now(g.tz), link, campaign))

        az_campaign = update_campaign(link)
        az_flight = update_flight(link, campaign, az_campaign)
        PromotionLog.add(link, 'deactivated %s' % az_flight)
开发者ID:curioussavage,项目名称:reddit-plugin-adzerk,代码行数:8,代码来源:adzerkpromote.py


示例15: _update_adzerk

def _update_adzerk(link, campaign):
    with g.make_lock('adzerk_update', 'adzerk-' + link._fullname):
        msg = '%s updating/creating adzerk objects for %s - %s'
        g.log.info(msg % (datetime.datetime.now(g.tz), link, campaign))
        az_campaign = update_campaign(link)
        az_creative = update_creative(link, campaign)
        az_flight = update_flight(link, campaign)
        az_cfmap = update_cfmap(link, campaign)
开发者ID:alienth,项目名称:reddit-plugin-adzerk,代码行数:8,代码来源:adzerkpromote.py


示例16: get_promoted_slow

def get_promoted_slow():
    # to be used only by a human at a terminal
    with g.make_lock(promoted_lock_key):
        links = Link._query(Link.c.promote_status == STATUS.promoted, Link.c.promoted == True, data=True)
        link_names = dict((x._fullname, auction_weight(x)) for x in links)

        set_promoted(link_names)

    return link_names
开发者ID:pastepotpete,项目名称:reddit,代码行数:9,代码来源:promote.py


示例17: auth_campaign

def auth_campaign(link, index, user, pay_id):
    """
    for setting up a campaign as a real bid with authorize.net
    """
    with g.make_lock(campaign_lock(link)):
        campaigns = getattr(link, "campaigns", {}).copy()
        if index in campaigns:
            # void any existing campaign
            void_campaign(link, index, user)

            sd, ed, bid, sr, trans_id = campaigns[index]
            # create a new transaction and update the bid
            test = 1 if g.debug else None
            trans_id, reason = authorize.auth_transaction(bid, user,
                                                          pay_id, link,
                                                          index,
                                                          test = test)
            if not reason and trans_id is not None and int(trans_id) != 0:
                promotion_log(link, "updated payment and/or bid for campaign %s: "
                              "SUCCESS (trans_id: %d, amt: %0.2f)"
                              % (index, trans_id, bid))
                if trans_id < 0:
                    promotion_log(link, "FREEBIE (campaign: %s)" % index)

                set_status(link,
                           max(STATUS.unseen if trans_id else STATUS.unpaid,
                               link.promote_status))
                # notify of campaign creation
                # update the query queue
                if user._id == link.author_id and trans_id > 0:
                    emailer.promo_bid(link, bid, sd)
            
            else:
                # something bad happend.
                promotion_log(link, "updated payment and/or bid for campaign %s: FAILED ('%s')" 
                              % (index, reason))
                trans_id = 0

            campaigns[index] = sd, ed, bid, sr, trans_id
            link.campaigns = {}
            link.campaigns = campaigns
            link._commit()

            # dual-write update to campaign Thing
            campaign = PromoCampaign._byID(index)
            if campaign:
                if trans_id > 0:
                    campaign.mark_paid(trans_id)
                elif trans_id < 0:
                    campaign.mark_freebie(trans_id)
                else:
                    campaign.mark_payment_error(reason)
                campaign._commit()

            return bool(trans_id), reason
        return False, ""
开发者ID:freekrai,项目名称:reddit,代码行数:56,代码来源:promote.py


示例18: link_comments

def link_comments(link_id):
    key = comments_key(link_id)
    r = g.permacache.get(key)
    if r:
        return r
    else:
        with g.make_lock(lock_key(link_id)):
            r = load_link_comments(link_id)
            g.permacache.set(key, r)
        return r
开发者ID:EmileKroeger,项目名称:lesswrong,代码行数:10,代码来源:comment_tree.py


示例19: get_blob

def get_blob(code):
    key = "payment_blob-" + code
    with g.make_lock("payment_blob", "payment_blob_lock-" + code):
        blob = g.hardcache.get(key)
        if not blob:
            raise NotFound("No payment_blob-" + code)
        if blob.get("status", None) != "initialized":
            raise ValueError("payment_blob %s has status = %s" % (code, blob.get("status", None)))
        blob["status"] = "locked"
        g.hardcache.set(key, blob, 86400 * 30)
    return key, blob
开发者ID:tolgaek,项目名称:reddit,代码行数:11,代码来源:ipn.py


示例20: delete_campaign

def delete_campaign(link, index):
    with g.make_lock(campaign_lock(link)):
        campaigns = getattr(link, "campaigns", {}).copy()
        if index in campaigns:
            PromotionWeights.delete_unfinished(link, index)
            del campaigns[index]
            link.campaigns = {}
            link.campaigns = campaigns
            link._commit()
            #TODO cancel any existing charges
            void_campaign(link, index, c.user)
开发者ID:JediWatchman,项目名称:reddit,代码行数:11,代码来源:promote.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python g.reset_caches函数代码示例发布时间:2022-05-25
下一篇:
Python util.get_pylons函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap