def __init__(self, capacity, root_dir): self.capacity = capacity os.makedirs(root_dir, exist_ok=True) self.root_dir = root_dir self._sum = np.memmap( os.path.join(self.root_dir, "sumtree-sum.dat"), mode="w+", dtype=np.float64, shape=capacity, ) self._sum.fill(0) self._min = np.memmap( os.path.join(self.root_dir, "sumtree-min.dat"), mode="w+", dtype=np.float64, shape=capacity, ) self._min.fill(0) self._val = np.memmap( os.path.join(self.root_dir, "sumtree-val.dat"), mode="w+", dtype=np.float64, shape=capacity, ) self._val.fill(0) self._lock = rwlock.RWLockWrite()
def setUp(self): """Test setup.""" self.v_value = 0 from readerwriterlock import rwlock self.c_rwlock_instance = [ rwlock.RWLockRead(), rwlock.RWLockWrite(), rwlock.RWLockFair() ]
def __init__(self, segment_dir): self.compaction_lock = Lock() self.compaction_thread = None self.segment_lock = rwlock.RWLockWrite() self.segment_dir = segment_dir self.segments = [] if path.isdir(self.segment_dir): self._load_segments() else: mkdir(self.segment_dir)
def __init__(self): self._connection_buffer = OrderedDict([]) ''' Buffer Structure: (sourceIP, sourcePort, dest_vIP, dest_rPort): (FIN (Flag received), rIP, enforced (should be used to continue connection)) enforced: Tell other modules that this connection should be kept alive (even if other security measures prohibit it) ''' self._max_buffer = 1000 self._mapping = None #Write Priority Lock self._lock = rwlock.RWLockWrite()
def __init__(self, percent_to_spend, instant=False, budget=None): self.lock = rwlock.RWLockWrite() self.buying_power = 0.0 self.instant = instant if budget is None: self.buying_power = float( r.profiles.load_account_profile(info='buying_power')) else: self.buying_power = min( float(r.profiles.load_account_profile(info='buying_power')), budget) self.amount_per_buy = self.buying_power * percent_to_spend
class StateLocker: """Synchronizes the state of file_transaction_svc""" __lock = rwlock.RWLockWrite() __current_service_state = None def get_lock(self): return self.__lock def get_current_service_state(self): return self.__current_service_state def set_current_service_state(self, new_state): self.__current_service_state = new_state
def __init__(self, db_manager, gatekeeper, carrier, block_processor): self.logger = get_logger(component=Responder.__name__) self.trackers = dict() self.tx_tracker_map = dict() self.unconfirmed_txs = [] self.missed_confirmations = dict() self.block_queue = Queue() self.db_manager = db_manager self.gatekeeper = gatekeeper self.carrier = carrier self.block_processor = block_processor self.last_known_block = db_manager.load_last_block_hash_responder() self.rw_lock = rwlock.RWLockWrite()
def __init__(self, user_db, block_processor, subscription_slots, subscription_duration, expiry_delta): self.subscription_slots = subscription_slots self.subscription_duration = subscription_duration self.expiry_delta = expiry_delta self.block_queue = Queue() self.block_processor = block_processor self.user_db = user_db self.registered_users = { user_id: UserInfo.from_dict(user_data) for user_id, user_data in user_db.load_all_users().items() } self.outdated_users_cache = {} self.rw_lock = rwlock.RWLockWrite() # Starts a child thread to take care of expiring subscriptions Thread(target=self.manage_subscription_expiry, daemon=True).start()
def __init__(self, db_manager, gatekeeper, block_processor, responder, sk, max_appointments, blocks_in_cache): self.logger = get_logger(component=Watcher.__name__) self.appointments = dict() self.locator_uuid_map = dict() self.block_queue = Queue() self.db_manager = db_manager self.gatekeeper = gatekeeper self.block_processor = block_processor self.responder = responder self.max_appointments = max_appointments self.signing_key = sk self.last_known_block = db_manager.load_last_block_hash_watcher() self.locator_cache = LocatorCache(blocks_in_cache) self.rw_lock = rwlock.RWLockWrite()
def __init__(self, curr_price, history_len, trend_len): """n MUST be a power of 2 >= 8 for the circular buffer to work, which is crucial for this class' operations to be O(1)""" assert(trend_len >= 2 and trend_len <= history_len) # k must be at least 2 self.lock = rwlock.RWLockWrite() # important: do not modify these two names, they are used by # strategies/simple_moving_average. unfortunate breach # of privacy but was necessary for speed gains self.prices = [float(curr_price)] self.ind = 1 self.history_len = history_len self.trend_len = trend_len self.mask = history_len-1 # 0b01111 if n is 16 self.has_price_update_occurred = False # track the first price of the day for EOD report self.first_price_seen = -1
def __new__(cls): # If the singleton has not been initialized yet, do so with the instance variables below if cls._grype_wrapper_instance is None: logger.debug("Initializing Grype wrapper instance.") # The singleton instance, only instantiated once outside of testing cls._grype_wrapper_instance = super(GrypeWrapperSingleton, cls).__new__(cls) # These variables are mutable, their state can be changed when grype_db is updated cls._grype_db_dir_internal = None cls._grype_db_version_internal = None cls._grype_db_session_maker_internal = None # These variables are also mutable. They are for staging updated grye_dbs. cls._staging_grype_db_dir_internal = None cls._staging_grype_db_version_internal = None cls._staging_grype_db_session_maker_internal = None # The reader-writer lock for this class cls._grype_db_lock = rwlock.RWLockWrite() # Return the singleton instance return cls._grype_wrapper_instance
from code.util.db import getKey, setKey, listSubKeys, deleteKey, Problem from uuid import uuid4 import logging import time from readerwriterlock import rwlock lock = rwlock.RWLockWrite() contests = {} class Contest: saveCallbacks = [] def __init__(self, id=None): if id != None: details = getKey(f"/contests/{id}/contest.json") self.id = details["id"] self.name = details["name"] self.start = int(details["start"]) self.end = int(details["end"]) self.scoreboardOff = int(details.get("scoreboardOff", self.end)) self.probInfoBlocks = details["probInfoBlocks"] == "True" self.problems = [Problem.get(id) for id in details["problems"]] if str(details["tieBreaker"]).lower() == "true": self.tieBreaker = True else: self.tieBreaker = False else: self.id = None
import collections import inspect import sys import logging import traceback from readerwriterlock import rwlock from pprint import pprint _THREADING_LOCK = rwlock.RWLockWrite() def _retrieve_class_path(obj): if not inspect.isclass(obj): raise Exception("Object must be a class") paths = obj.__module__.split(".") paths.append(obj.__qualname__) return paths class ObjectFactoryMap(dict): def __init__(self, *args, **kwargs): self.update(*args, **kwargs) for arg in args: if isinstance(arg, dict): for k, v in arg.items(): self[k] = v if kwargs: for k, v in kwargs.items(): self[k] = v
def __init__(self, path): self.__dict__['state_internal'] = dict() self.__dict__['rwlock'] = rwlock.RWLockWrite() self.__dict__['path'] = path
def __init__(self, blocks_in_cache): self.cache = dict() self.blocks = OrderedDict() self.cache_size = blocks_in_cache self.rw_lock = rwlock.RWLockWrite()
from git import Repo import os import shutil from multiprocessing.pool import ThreadPool import sys from conf import config sys.path.append(os.path.realpath('..')) from wrapper.async_wrapper import run_async_multiprocessing # Example: https://api.github.com/search/repositories?q=stars:<=10000+language:java&sort=stars&order=desc&per_page=100&page=1 # Setup io lock try: from readerwriterlock import rwlock lock = rwlock.RWLockWrite().gen_wlock() except ImportError: from threading import Lock lock = Lock() def _read_conf(conf_path): df_conf = pd.read_csv(conf_path) return list(df_conf['ProjectInfo']) def _create_if_not_exist(p, isFile=False): if isFile: # Delete file if exist if os.path.isfile(p): os.remove(p)
def __init__(self, dict_cls: typing.Type = dict) -> None: self._dict = dict_cls() self._guard = rwlock.RWLockWrite()
def __init__(self, blocks_in_cache): self.logger = get_logger(component=LocatorCache.__name__) self.cache = dict() self.blocks = OrderedDict() self.cache_size = blocks_in_cache self.rw_lock = rwlock.RWLockWrite()
def __init__(self, capacity): self.capacity = capacity self._sum = np.zeros(capacity, dtype=np.float64) self._min = np.zeros(capacity, dtype=np.float64) self._val = np.zeros(capacity, dtype=np.float64) self._lock = rwlock.RWLockWrite()