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

Python pinning.unpin_this_thread函数代码示例

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

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



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

示例1: log_answer

def log_answer(answer):
    pin_this_thread()

    creator = answer.creator
    created = answer.created
    question = answer.question
    users = [a.creator for a in
             question.answers.select_related('creator').exclude(
                creator=creator)]
    if question.creator != creator:
        users += [question.creator]
    users = set(users)  # Remove duplicates.

    if users:
        action = Action.objects.create(
            creator=creator,
            created=created,
            url=answer.get_absolute_url(),
            content_object=answer,
            formatter_cls='questions.formatters.AnswerFormatter')
        action.users.add(*users)

    transaction.commit_unless_managed()

    # Record karma actions
    AnswerAction(answer.creator, answer.created.date()).save()
    if answer == answer.question.answers.order_by('created')[0]:
        FirstAnswerAction(answer.creator, answer.created.date()).save()

    unpin_this_thread()
开发者ID:chengwang,项目名称:kitsune,代码行数:30,代码来源:tasks.py


示例2: _rebuild_kb_chunk

def _rebuild_kb_chunk(data, **kwargs):
    """Re-render a chunk of documents."""
    log.info('Rebuilding %s documents.' % len(data))

    pin_this_thread()  # Stick to master.

    messages = []
    for pk in data:
        message = None
        try:
            document = Document.objects.get(pk=pk)
            document.html = document.current_revision.content_cleaned
            document.save()
        except Document.DoesNotExist:
            message = 'Missing document: %d' % pk
        except ValidationError as e:
            message = 'ValidationError for %d: %s' % (pk, e.messages[0])
        except SlugCollision:
            message = 'SlugCollision: %d' % pk
        except TitleCollision:
            message = 'TitleCollision: %d' % pk

        if message:
            log.debug(message)
            messages.append(message)

    if messages:
        subject = ('[%s] Exceptions raised in _rebuild_kb_chunk()' %
                   settings.PLATFORM_NAME)
        mail_admins(subject=subject, message='\n'.join(messages))
    transaction.commit_unless_managed()

    unpin_this_thread()  # Not all tasks need to do use the master.
开发者ID:tantek,项目名称:kuma,代码行数:33,代码来源:tasks.py


示例3: _rebuild_kb_chunk

def _rebuild_kb_chunk(data):
    """Re-render a chunk of documents.

    Note: Don't use host components when making redirects to wiki pages; those
    redirects won't be auto-pruned when they're 404s.

    """
    log.info('Rebuilding %s documents.' % len(data))

    pin_this_thread()  # Stick to master.

    messages = []
    start = time.time()
    for pk in data:
        message = None
        try:
            document = Document.objects.get(pk=pk)

            # If we know a redirect link to be broken (i.e. if it looks like a
            # link to a document but the document isn't there), log an error:
            url = document.redirect_url()
            if (url and points_to_document_view(url) and
                    not document.redirect_document()):
                log.warn('Invalid redirect document: %d' % pk)

            html = document.parse_and_calculate_links()
            if document.html != html:
                # We are calling update here to so we only update the html
                # column instead of all of them. This bypasses post_save
                # signal handlers like the one that triggers reindexing.
                # See bug 797038 and bug 797352.
                Document.objects.filter(pk=pk).update(html=html)
                statsd.incr('wiki.rebuild_chunk.change')
            else:
                statsd.incr('wiki.rebuild_chunk.nochange')
        except Document.DoesNotExist:
            message = 'Missing document: %d' % pk
        except Revision.DoesNotExist:
            message = 'Missing revision for document: %d' % pk
        except ValidationError as e:
            message = 'ValidationError for %d: %s' % (pk, e.messages[0])
        except SlugCollision:
            message = 'SlugCollision: %d' % pk
        except TitleCollision:
            message = 'TitleCollision: %d' % pk

        if message:
            log.debug(message)
            messages.append(message)
    d = time.time() - start
    statsd.timing('wiki.rebuild_chunk', int(round(d * 1000)))

    if messages:
        subject = ('[%s] Exceptions raised in _rebuild_kb_chunk()' %
                   settings.PLATFORM_NAME)
        mail_admins(subject=subject, message='\n'.join(messages))
    if not transaction.get_connection().in_atomic_block:
        transaction.commit()

    unpin_this_thread()  # Not all tasks need to do use the master.
开发者ID:1234-,项目名称:kitsune,代码行数:60,代码来源:tasks.py


示例4: render_document_cascade

def render_document_cascade(base):
    """Given a document, render it and all documents that may be affected."""

    # This walks along the graph of links between documents. If there is
    # a document A that includes another document B as a template, then
    # there is an edge from A to B in this graph. The goal here is to
    # process every node exactly once. This is robust to cycles and
    # diamonds in the graph, since it keeps track of what nodes have
    # been visited already.

    # In case any thing goes wrong, this guarantees we unpin the DB
    try:
        # Sends all writes to the master DB. Slaves are readonly.
        pin_this_thread()

        todo = set([base])
        done = set()

        while todo:
            d = todo.pop()
            if d in done:
                # Don't process a node twice.
                continue
            d.html = d.parse_and_calculate_links()
            d.save()
            done.add(d)
            todo.update(l.linked_from for l in d.links_to()
                        .filter(kind__in=['template', 'include']))

    finally:
        unpin_this_thread()
开发者ID:1234-,项目名称:kitsune,代码行数:31,代码来源:tasks.py


示例5: setUp

 def setUp(self):
     self.auth = authentication.RestSharedSecretAuthentication()
     self.profile = UserProfile.objects.get(pk=2519)
     self.profile.update(email=self.profile.email)
     self.middlewares = [APIBaseMiddleware,
                         RestSharedSecretMiddleware]
     unpin_this_thread()
开发者ID:JaredKerim-Mozilla,项目名称:zamboni,代码行数:7,代码来源:test_authentication.py


示例6: index_task

def index_task(cls, id_list, **kw):
    """Index documents specified by cls and ids"""
    statsd.incr('search.tasks.index_task.%s' % cls.get_mapping_type_name())
    try:
        # Pin to master db to avoid replication lag issues and stale
        # data.
        pin_this_thread()

        qs = cls.get_model().uncached.filter(id__in=id_list).values_list(
            'id', flat=True)
        for id_ in qs:
            try:
                cls.index(cls.extract_document(id_), id_=id_)
            except UnindexMeBro:
                # If extract_document throws this, then we need to
                # remove this item from the index.
                cls.unindex(id_)

    except Exception as exc:
        retries = index_task.request.retries
        if retries >= MAX_RETRIES:
            # Some exceptions aren't pickleable and we need this to
            # throw things that are pickleable.
            raise IndexingTaskError()

        statsd.incr('search.tasks.index_task.retry', 1)
        statsd.incr('search.tasks.index_task.retry%d' % RETRY_TIMES[retries],
                    1)

        index_task.retry(exc=exc, max_retries=MAX_RETRIES,
                         countdown=RETRY_TIMES[retries])
    finally:
        unpin_this_thread()
开发者ID:PatMart,项目名称:kitsune,代码行数:33,代码来源:tasks.py


示例7: index_chunk_task

def index_chunk_task(index, batch_id, rec_id, chunk):
    """Index a chunk of things.

    :arg index: the name of the index to index to
    :arg batch_id: the name for the batch this chunk belongs to
    :arg rec_id: the id for the record for this task
    :arg chunk: a (class, id_list) of things to index
    """
    cls, id_list = chunk

    try:
        # Pin to master db to avoid replication lag issues and stale
        # data.
        pin_this_thread()

        # Update record data.
        rec = Record.objects.get(pk=rec_id)
        rec.start_time = datetime.datetime.now()
        rec.message = u'Reindexing into %s' % index
        rec.status = Record.STATUS_IN_PROGRESS
        rec.save()

        index_chunk(cls, id_list, reraise=True)

        rec.mark_success()

    except Exception:
        rec.mark_fail(u'Errored out %s %s' % (
                sys.exc_type, sys.exc_value))
        raise

    finally:
        unpin_this_thread()
开发者ID:milossh,项目名称:fjord,代码行数:33,代码来源:tasks.py


示例8: test_pinning_encapsulation

 def test_pinning_encapsulation(self):
     """Check the pinning getters and setters."""
     self.assertFalse(this_thread_is_pinned())
     pin_this_thread()
     self.assertTrue(this_thread_is_pinned())
     unpin_this_thread()
     self.assertFalse(this_thread_is_pinned())
开发者ID:wikical,项目名称:django-multidb-router,代码行数:7,代码来源:test_all.py


示例9: test_context_manager_exception

 def test_context_manager_exception(self):
     unpin_this_thread()
     assert not this_thread_is_pinned()
     with self.assertRaises(ValueError):
         with use_master:
             assert this_thread_is_pinned()
             raise ValueError
     assert not this_thread_is_pinned()
开发者ID:mapmyfitness,项目名称:django-multidb-router,代码行数:8,代码来源:__init__.py


示例10: process_request

 def process_request(self, request):
     """Set the thread's pinning flag according to the presence of the
     incoming cookie."""
     if PINNING_COOKIE in request.COOKIES or request.method not in READ_ONLY_METHODS:
         pin_this_thread()
     else:
         # In case the last request this thread served was pinned:
         unpin_this_thread()
开发者ID:Mondego,项目名称:pyreco,代码行数:8,代码来源:allPythonContent.py


示例11: test_decorator

 def test_decorator(self):
     @use_primary_db
     def check():
         assert this_thread_is_pinned()
     unpin_this_thread()
     assert not this_thread_is_pinned()
     check()
     assert not this_thread_is_pinned()
开发者ID:jbalogh,项目名称:django-multidb-router,代码行数:8,代码来源:tests.py


示例12: test_context_manager_exception

 def test_context_manager_exception(self):
     unpin_this_thread()
     self.assertFalse(this_thread_is_pinned())
     with self.assertRaises(ValueError):
         with use_master:
             self.assertTrue(this_thread_is_pinned())
             raise ValueError
     self.assertFalse(this_thread_is_pinned())
开发者ID:wikical,项目名称:django-multidb-router,代码行数:8,代码来源:test_all.py


示例13: test_decorator

 def test_decorator(self):
     @use_master
     def check():
         assert this_thread_is_pinned()
     unpin_this_thread()
     assert not this_thread_is_pinned()
     check()
     assert not this_thread_is_pinned()
开发者ID:mapmyfitness,项目名称:django-multidb-router,代码行数:8,代码来源:__init__.py


示例14: setUp

 def setUp(self):
     self.api_name = "foo"
     self.profile = UserProfile.objects.get(pk=2519)
     self.profile.update(read_dev_agreement=datetime.today())
     self.access = Access.objects.create(key="test_oauth_key", secret=generate(), user=self.profile.user)
     self.auth = authentication.RestOAuthAuthentication()
     self.middlewares = [RedirectPrefixedURIMiddleware, RestOAuthMiddleware]
     unpin_this_thread()
开发者ID:robhudson,项目名称:zamboni,代码行数:8,代码来源:test_authentication.py


示例15: setUp

 def setUp(self):
     self.api_name = 'foo'
     self.profile = UserProfile.objects.get(pk=2519)
     self.profile.update(read_dev_agreement=datetime.today())
     self.access = Access.objects.create(key='test_oauth_key',
                                         secret=generate(),
                                         user=self.profile.user)
     self.auth = authentication.RestOAuthAuthentication()
     unpin_this_thread()
开发者ID:aricha,项目名称:zamboni,代码行数:9,代码来源:test_authentication.py


示例16: test_pinning_encapsulation

    def test_pinning_encapsulation(self):
        """Check the pinning getters and setters."""
        assert not this_thread_is_pinned(), "Thread started out pinned or this_thread_is_pinned() is broken."

        pin_this_thread()
        assert this_thread_is_pinned(), "pin_this_thread() didn't pin the thread."

        unpin_this_thread()
        assert not this_thread_is_pinned(), "Thread remained pinned after unpin_this_thread()."
开发者ID:Mondego,项目名称:pyreco,代码行数:9,代码来源:allPythonContent.py


示例17: test_decorator

    def test_decorator(self):

        @use_master
        def check():
            self.assertTrue(this_thread_is_pinned())

        unpin_this_thread()
        self.assertFalse(this_thread_is_pinned())
        check()
        self.assertFalse(this_thread_is_pinned())
开发者ID:wikical,项目名称:django-multidb-router,代码行数:10,代码来源:test_all.py


示例18: test_slave_decorator_resets

    def test_slave_decorator_resets(self):

        @use_slave
        def check():
            self.assertFalse(this_thread_is_pinned())

        unpin_this_thread()
        self.assertFalse(this_thread_is_pinned())
        check()
        self.assertFalse(this_thread_is_pinned())
开发者ID:clearcare,项目名称:django-multidb-router,代码行数:10,代码来源:test_all.py


示例19: test_context_manager_exception

 def test_context_manager_exception(self):
     unpin_this_thread()
     try:
         assert not this_thread_is_pinned()
         with use_master:
             assert this_thread_is_pinned()
             raise ValueError
     except ValueError:
         pass
     assert not this_thread_is_pinned()
开发者ID:Marlburo,项目名称:inventory,代码行数:10,代码来源:__init__.py


示例20: setUp

 def setUp(self):
     self.api_name = 'foo'
     self.profile = UserProfile.objects.get(pk=2519)
     self.profile.update(read_dev_agreement=datetime.today())
     self.access = Access.objects.create(key='test_oauth_key',
                                         secret='super secret',
                                         user=self.profile)
     self.auth = authentication.RestOAuthAuthentication()
     self.middlewares = [APIBaseMiddleware, RestOAuthMiddleware]
     unpin_this_thread()
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:10,代码来源:test_authentication.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python multidict.upstr函数代码示例发布时间:2022-05-27
下一篇:
Python pinning.this_thread_is_pinned函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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