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


Python g.make_lock函数代码示例

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


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


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