Python threading.RLock() Examples
The following are 30
code examples of threading.RLock().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
threading
, or try the search function
.
Example #1
Source File: template.py From tornado-zh with MIT License | 6 votes |
def __init__(self, autoescape=_DEFAULT_AUTOESCAPE, namespace=None, whitespace=None): """构造一个模板加载器. :arg str autoescape: 在模板命名空间中的函数名, 例如 "xhtml_escape", 或默认情况下为 ``None`` 来禁用自动转义. :arg dict namespace: 一个被加入默认模板命名空间中的字典或 ``None``. :arg str whitespace: 一个指定模板中whitespace默认行为的字符串; 参见 `filter_whitespace` 查看可选项. 默认是 "single" 对于 ".html" 和 ".js" 文件的结束, "all" 是为了其他文件. .. versionchanged:: 4.3 添加 ``whitespace`` 参数. """ self.autoescape = autoescape self.namespace = namespace or {} self.whitespace = whitespace self.templates = {} # self.lock protects self.templates. It's a reentrant lock # because templates may load other templates via `include` or # `extends`. Note that thanks to the GIL this code would be safe # even without the lock, but could lead to wasted work as multiple # threads tried to compile the same template simultaneously. self.lock = threading.RLock()
Example #2
Source File: template.py From tornado-zh with MIT License | 6 votes |
def __init__(self, autoescape=_DEFAULT_AUTOESCAPE, namespace=None, whitespace=None): """构造一个模板加载器. :arg str autoescape: 在模板命名空间中的函数名, 例如 "xhtml_escape", 或默认情况下为 ``None`` 来禁用自动转义. :arg dict namespace: 一个被加入默认模板命名空间中的字典或 ``None``. :arg str whitespace: 一个指定模板中whitespace默认行为的字符串; 参见 `filter_whitespace` 查看可选项. 默认是 "single" 对于 ".html" 和 ".js" 文件的结束, "all" 是为了其他文件. .. versionchanged:: 4.3 添加 ``whitespace`` 参数. """ self.autoescape = autoescape self.namespace = namespace or {} self.whitespace = whitespace self.templates = {} # self.lock protects self.templates. It's a reentrant lock # because templates may load other templates via `include` or # `extends`. Note that thanks to the GIL this code would be safe # even without the lock, but could lead to wasted work as multiple # threads tried to compile the same template simultaneously. self.lock = threading.RLock()
Example #3
Source File: application_configuration.py From browserscope with Apache License 2.0 | 6 votes |
def __init__(self, app_yaml_path, backend_yaml_path): """Initializer for BackendsConfiguration. Args: app_yaml_path: A string containing the full path of the yaml file containing the configuration for this server. backend_yaml_path: A string containing the full path of the backends.yaml file containing the configuration for backends. """ self._update_lock = threading.RLock() self._base_server_configuration = ServerConfiguration(app_yaml_path) backend_info_external = self._parse_configuration( backend_yaml_path) self._backends_name_to_backend_entry = {} for backend in backend_info_external.backends or []: self._backends_name_to_backend_entry[backend.name] = backend self._changes = dict( (backend_name, set()) for backend_name in self._backends_name_to_backend_entry)
Example #4
Source File: decorators.py From ratelimit with MIT License | 6 votes |
def __init__(self, calls=15, period=900, clock=now(), raise_on_limit=True): ''' Instantiate a RateLimitDecorator with some sensible defaults. By default the Twitter rate limiting window is respected (15 calls every 15 minutes). :param int calls: Maximum function invocations allowed within a time period. :param float period: An upper bound time period (in seconds) before the rate limit resets. :param function clock: An optional function retuning the current time. :param bool raise_on_limit: A boolean allowing the caller to avoiding rasing an exception. ''' self.clamped_calls = max(1, min(sys.maxsize, floor(calls))) self.period = period self.clock = clock self.raise_on_limit = raise_on_limit # Initialise the decorator state. self.last_reset = clock() self.num_calls = 0 # Add thread safety. self.lock = threading.RLock()
Example #5
Source File: locators.py From recruit with Apache License 2.0 | 6 votes |
def __init__(self, url, timeout=None, num_workers=10, **kwargs): """ Initialise an instance. :param url: The root URL to use for scraping. :param timeout: The timeout, in seconds, to be applied to requests. This defaults to ``None`` (no timeout specified). :param num_workers: The number of worker threads you want to do I/O, This defaults to 10. :param kwargs: Passed to the superclass. """ super(SimpleScrapingLocator, self).__init__(**kwargs) self.base_url = ensure_slash(url) self.timeout = timeout self._page_cache = {} self._seen = set() self._to_fetch = queue.Queue() self._bad_hosts = set() self.skip_externals = False self.num_workers = num_workers self._lock = threading.RLock() # See issue #45: we need to be resilient when the locator is used # in a thread, e.g. with concurrent.futures. We can't use self._lock # as it is for coordinating our internal threads - the ones created # in _prepare_threads. self._gplock = threading.RLock()
Example #6
Source File: __init__.py From jawfish with MIT License | 6 votes |
def _checkLevel(level): if isinstance(level, int): rv = level elif str(level) == level: if level not in _levelNames: raise ValueError("Unknown level: %r" % level) rv = _levelNames[level] else: raise TypeError("Level not an integer or a valid string: %r" % level) return rv #--------------------------------------------------------------------------- # Thread-related stuff #--------------------------------------------------------------------------- # #_lock is used to serialize access to shared data structures in this module. #This needs to be an RLock because fileConfig() creates and configures #Handlers, and so might arbitrary user threads. Since Handler code updates the #shared dictionary _handlers, it needs to acquire the lock. But if configuring, #the lock would already have been acquired - so we need an RLock. #The same argument applies to Loggers and Manager.loggerDict. #
Example #7
Source File: incremental.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
def __init__(self, serializer, input_data, chunk_size, string_max_len=None): super(IncrementalPandasToRecArraySerializer, self).__init__(serializer, input_data, chunk_size) if not isinstance(serializer, PandasSerializer): raise ArcticSerializationException("IncrementalPandasToRecArraySerializer requires a serializer of " "type PandasSerializer.") if not isinstance(input_data, (pd.DataFrame, pd.Series)): raise ArcticSerializationException("IncrementalPandasToRecArraySerializer requires a pandas DataFrame or " "Series as data source input.") if string_max_len and string_max_len < 1: raise ArcticSerializationException("IncrementalPandasToRecArraySerializer can't be initialized " "with string_max_len < 1 ({})".format(string_max_len)) self.string_max_len = string_max_len # The state which needs to be lazily initialized self._dtype = None self._shape = None self._rows_per_chunk = 0 self._total_chunks = 0 self._has_string_object = False self._lock = RLock()
Example #8
Source File: _workers_pool.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
def __init__(self, pool_size): # Only allow creation via get_instance if not type(self)._SINGLETON_LOCK._is_owned(): raise AsyncArcticException("{} is a singleton, can't create a new instance".format(type(self))) pool_size = int(pool_size) if pool_size < 1: raise ValueError("{} can't be instantiated with a pool_size of {}".format(type(self), pool_size)) # Enforce the singleton pattern with type(self)._SINGLETON_LOCK: if type(self)._instance is not None: raise AsyncArcticException("LazySingletonTasksCoordinator is a singleton, can't create a new instance") self._lock = RLock() self._pool = None self._pool_size = int(pool_size) self._pool_update_hooks = [] self.alive_tasks = {} self.is_shutdown = False
Example #9
Source File: dispatcher.py From browserscope with Apache License 2.0 | 5 votes |
def __init__(self): self._ports = {} self._ports_lock = threading.RLock()
Example #10
Source File: _collections.py From ServerlessCrawler-VancouverRealState with MIT License | 5 votes |
def __init__(self, maxsize=10, dispose_func=None): self._maxsize = maxsize self.dispose_func = dispose_func self._container = self.ContainerCls() self.lock = RLock()
Example #11
Source File: __init__.py From jieba_fast with MIT License | 5 votes |
def __init__(self, dictionary=DEFAULT_DICT): self.lock = threading.RLock() if dictionary == DEFAULT_DICT: self.dictionary = dictionary else: self.dictionary = _get_abs_path(dictionary) self.FREQ = {} self.total = 0 self.user_word_tag_tab = {} self.initialized = False self.tmp_dir = None self.cache_file = None
Example #12
Source File: _collections.py From recruit with Apache License 2.0 | 5 votes |
def __init__(self, maxsize=10, dispose_func=None): self._maxsize = maxsize self.dispose_func = dispose_func self._container = self.ContainerCls() self.lock = RLock()
Example #13
Source File: cookies.py From recruit with Apache License 2.0 | 5 votes |
def __getstate__(self): """Unlike a normal CookieJar, this class is pickleable.""" state = self.__dict__.copy() # remove the unpickleable RLock object state.pop('_cookies_lock') return state
Example #14
Source File: cookies.py From recruit with Apache License 2.0 | 5 votes |
def __setstate__(self, state): """Unlike a normal CookieJar, this class is pickleable.""" self.__dict__.update(state) if '_cookies_lock' not in self.__dict__: self._cookies_lock = threading.RLock()
Example #15
Source File: _collections.py From ServerlessCrawler-VancouverRealState with MIT License | 5 votes |
def __init__(self, maxsize=10, dispose_func=None): self._maxsize = maxsize self.dispose_func = dispose_func self._container = self.ContainerCls() self.lock = RLock()
Example #16
Source File: database.py From Pyro5 with MIT License | 5 votes |
def __init__(self, db, user=None): self.db = db self.user = user self.lock = threading.RLock()
Example #17
Source File: nameserver.py From Pyro5 with MIT License | 5 votes |
def __init__(self, storageProvider=None): self.storage = storageProvider if storageProvider is None: self.storage = MemoryStorage() log.debug("using volatile in-memory dict storage") self.lock = threading.RLock()
Example #18
Source File: helpers.py From recruit with Apache License 2.0 | 5 votes |
def __init__(self, func, name=None, doc=None): self.__name__ = name or func.__name__ self.__module__ = func.__module__ self.__doc__ = doc or func.__doc__ self.func = func self.lock = RLock()
Example #19
Source File: __init__.py From jieba_fast with MIT License | 5 votes |
def __init__(self, dictionary=DEFAULT_DICT): self.lock = threading.RLock() if dictionary == DEFAULT_DICT: self.dictionary = dictionary else: self.dictionary = _get_abs_path(dictionary) self.FREQ = {} self.total = 0 self.user_word_tag_tab = {} self.initialized = False self.tmp_dir = None self.cache_file = None
Example #20
Source File: cookies.py From ServerlessCrawler-VancouverRealState with MIT License | 5 votes |
def __getstate__(self): """Unlike a normal CookieJar, this class is pickleable.""" state = self.__dict__.copy() # remove the unpickleable RLock object state.pop('_cookies_lock') return state
Example #21
Source File: _collections.py From ServerlessCrawler-VancouverRealState with MIT License | 5 votes |
def __init__(self, maxsize=10, dispose_func=None): self._maxsize = maxsize self.dispose_func = dispose_func self._container = self.ContainerCls() self.lock = RLock()
Example #22
Source File: cookies.py From ServerlessCrawler-VancouverRealState with MIT License | 5 votes |
def __setstate__(self, state): """Unlike a normal CookieJar, this class is pickleable.""" self.__dict__.update(state) if '_cookies_lock' not in self.__dict__: self._cookies_lock = threading.RLock()
Example #23
Source File: cookies.py From ServerlessCrawler-VancouverRealState with MIT License | 5 votes |
def __getstate__(self): """Unlike a normal CookieJar, this class is pickleable.""" state = self.__dict__.copy() # remove the unpickleable RLock object state.pop('_cookies_lock') return state
Example #24
Source File: _collections.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
def __init__(self, maxsize=10, dispose_func=None): self._maxsize = maxsize self.dispose_func = dispose_func self._container = self.ContainerCls() self.lock = RLock()
Example #25
Source File: arctic.py From arctic with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self, arctic, library): self.arctic = arctic self._curr_conn = self.arctic._conn self._lock = threading.RLock() database_name, library = self._parse_db_lib(library) self.library = library self.database_name = database_name self._auth(self.arctic._conn[self.database_name])
Example #26
Source File: tb_device_mqtt.py From thingsboard-gateway with Apache License 2.0 | 5 votes |
def __init__(self, host, port=1883, token=None): self._client = paho.Client() self.__host = host self.__port = port if token == "": log.warning("token is not set, connection without tls wont be established") else: self._client.username_pw_set(token) self._lock = RLock() self._attr_request_dict = {} self.stopped = False self.__timeout_queue = queue.Queue() self.__timeout_thread = Thread(target=self.__timeout_check) self.__timeout_thread.daemon = True self.__timeout_thread.start() self.__is_connected = False self.__device_on_server_side_rpc_response = None self.__connect_callback = None self.__device_max_sub_id = 0 self.__device_client_rpc_number = 0 self.__device_sub_dict = {} self.__device_client_rpc_dict = {} self.__attr_request_number = 0 self._client.on_connect = self._on_connect # self._client.on_log = self._on_log self._client.on_publish = self._on_publish self._client.on_message = self._on_message self._client.on_disconnect = self._on_disconnect # def _on_log(self, client, userdata, level, buf): # if isinstance(buf, Exception): # log.exception(buf) # else: # log.debug("%s - %s - %s - %s", client, userdata, level, buf)
Example #27
Source File: cookies.py From core with MIT License | 5 votes |
def __setstate__(self, state): """Unlike a normal CookieJar, this class is pickleable.""" self.__dict__.update(state) if '_cookies_lock' not in self.__dict__: self._cookies_lock = threading.RLock()
Example #28
Source File: cookies.py From core with MIT License | 5 votes |
def __getstate__(self): """Unlike a normal CookieJar, this class is pickleable.""" state = self.__dict__.copy() # remove the unpickleable RLock object state.pop('_cookies_lock') return state
Example #29
Source File: _collections.py From core with MIT License | 5 votes |
def __init__(self, maxsize=10, dispose_func=None): self._maxsize = maxsize self.dispose_func = dispose_func self._container = self.ContainerCls() self.lock = RLock()
Example #30
Source File: sessions.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def acquire_lock(self): """Acquire an exclusive lock on the currently-loaded session data.""" self.locked = True self.locks.setdefault(self.id, threading.RLock()).acquire()