Пример #1
0
 def test_thread_local(self):
     local = ThreadLocal(a=1, b=2)
     local.b = 3
     local.c = 4
     local_dict = [local.__dict__.copy()]
     def f():
         local.b = 5
         local.d = 6
         local_dict.append(local.__dict__.copy())
     thread = threading.Thread(target=f)
     thread.start()
     thread.join()
     self.assertEqual(dict(a=1, b=3, c=4), local_dict[0])
     self.assertEqual(dict(a=1, b=5, d=6), local_dict[1])
Пример #2
0
 def test_thread_local(self):
     local = ThreadLocal(a=1, b=2)
     local.b = 3
     local.c = 4
     local_dict = [local.__dict__.copy()]
     def f():
         local.b = 5
         local.d = 6
         local_dict.append(local.__dict__.copy())
     thread = threading.Thread(target=f)
     thread.start()
     thread.join()
     self.assertEqual(dict(a=1, b=3, c=4), local_dict[0])
     self.assertEqual(dict(a=1, b=5, d=6), local_dict[1])
Пример #3
0
Файл: api.py Проект: ohanar/trac
def make_env(get_cnx):
    return Mock(
        components={
            DatabaseManager:
            Mock(get_connection=get_cnx,
                 _transaction_local=ThreadLocal(wdb=None, rdb=None))
        })
Пример #4
0
def make_env(get_cnx):
    from trac.core import ComponentManager
    return Mock(ComponentManager,
                components={
                    DatabaseManager:
                    Mock(get_connection=get_cnx,
                         _transaction_local=ThreadLocal(wdb=None, rdb=None))
                })
Пример #5
0
 def __init__(self):
     self._current = ThreadLocal(args=None, translations=None)
     self._null_translations = NullTranslationsBabel()
     self._plugin_domains = {}
     self._plugin_domains_lock = threading.RLock()
     self._activate_failed = False
Пример #6
0
from __future__ import with_statement

import os
import urllib
import time

from trac.config import BoolOption, IntOption, Option
from trac.core import *
from trac.util.concurrency import ThreadLocal
from trac.util.text import unicode_passwd
from trac.util.translation import _

from .pool import ConnectionPool
from .util import ConnectionWrapper

_transaction_local = ThreadLocal(wdb=None, rdb=None)


def with_transaction(env, db=None):
    """Function decorator to emulate a context manager for database
    transactions.

    >>> def api_method(p1, p2):
    >>>     result[0] = value1
    >>>     @with_transaction(env)
    >>>     def implementation(db):
    >>>         # implementation
    >>>         result[0] = value2
    >>>     return result[0]

    :deprecated: use instead the new context manager:
Пример #7
0
 def __init__(self):
     self._cnx_pool = None
     self._transaction_local = ThreadLocal(wdb=None, rdb=None)
Пример #8
0
 def __init__(self):
     self._cache = {}
     self._local = ThreadLocal(meta=None, cache=None)
     self._lock = threading.RLock()
Пример #9
0
# history and logs, available at http://trac.edgewall.org/log/.
#
# Author: Christopher Lenz <*****@*****.**>

import os
import urllib
import time

from trac.config import BoolOption, IntOption, Option
from trac.core import *
from trac.db.pool import ConnectionPool
from trac.util.concurrency import ThreadLocal
from trac.util.text import unicode_passwd
from trac.util.translation import _

_transaction_local = ThreadLocal(db=None)


def with_transaction(env, db=None):
    """Function decorator to emulate a context manager for database
    transactions.
    
    >>> def api_method(p1, p2):
    >>>     result[0] = value1
    >>>     @with_transaction(env)
    >>>     def implementation(db):
    >>>         # implementation
    >>>         result[0] = value2
    >>>     return result[0]
    
    In this example, the `implementation()` function is called automatically