本文整理匯總了Python中multiprocessing.RLock方法的典型用法代碼示例。如果您正苦於以下問題:Python multiprocessing.RLock方法的具體用法?Python multiprocessing.RLock怎麽用?Python multiprocessing.RLock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing
的用法示例。
在下文中一共展示了multiprocessing.RLock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: initialize_unittest_logging
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def initialize_unittest_logging():
# ACE is multi-process multi-threaded
# so we use this special logging mechanism to keep a central repository of the log events generated
# that the original process can access
global test_log_manager
global test_log_sync
global test_log_messages
global memory_log_handler
test_log_manager = Manager()
atexit.register(_atexit_callback)
test_log_sync = RLock()
test_log_messages = test_log_manager.list()
log_format = logging.Formatter(datefmt='%(asctime)s')
memory_log_handler = MemoryLogHandler()
memory_log_handler.setLevel(logging.DEBUG)
memory_log_handler.setFormatter(log_format)
logging.getLogger().addHandler(memory_log_handler)
示例2: _edit_lock
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def _edit_lock(self):
# type: () -> ()
if self.__edit_lock:
return self.__edit_lock
if not PROC_MASTER_ID_ENV_VAR.get() or len(PROC_MASTER_ID_ENV_VAR.get().split(':')) < 2:
self.__edit_lock = RLock()
elif PROC_MASTER_ID_ENV_VAR.get().split(':')[1] == str(self.id):
# remove previous file lock instance, just in case.
filename = os.path.join(gettempdir(), 'trains_{}.lock'.format(self.id))
# noinspection PyBroadException
try:
os.unlink(filename)
except Exception:
pass
# create a new file based lock
self.__edit_lock = FileRLock(filename=filename)
else:
self.__edit_lock = RLock()
return self.__edit_lock
示例3: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def __init__(self, auth_handler, update_interval, accept_lang,
country_code, excluded_cars, save_car_details,
pin, save_path):
self.__lock = RLock()
self.accept_lang = accept_lang
self.country_code = country_code
self.auth_handler = auth_handler
self.cars = []
self.update_interval = update_interval
self.excluded_cars = excluded_cars
self.is_valid_session = False
self.last_update_time = 0
self.save_car_details = save_car_details
self.save_path = save_path
self.pin = pin
self.region = "-an" if country_code == "US" else ""
self.session = requests.session()
# self.session.proxies.update(HTTP_PROXY)
_LOGGER.debug("Controller init complete. Start _get_cars")
self._get_cars()
示例4: test_rlock
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def test_rlock(self):
lock = self.RLock()
self.assertEqual(lock.acquire(), True)
self.assertEqual(lock.acquire(), True)
self.assertEqual(lock.acquire(), True)
self.assertEqual(lock.release(), None)
self.assertEqual(lock.release(), None)
self.assertEqual(lock.release(), None)
self.assertRaises((AssertionError, RuntimeError), lock.release)
示例5: Value
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def Value(typecode_or_type, *args, **kwds):
'''
Return a synchronization wrapper for a Value
'''
lock = kwds.pop('lock', None)
if kwds:
raise ValueError('unrecognized keyword argument(s): %s' % kwds.keys())
obj = RawValue(typecode_or_type, *args)
if lock is False:
return obj
if lock in (True, None):
lock = RLock()
if not hasattr(lock, 'acquire'):
raise AttributeError("'%r' has no method 'acquire'" % lock)
return synchronized(obj, lock)
示例6: Array
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def Array(typecode_or_type, size_or_initializer, **kwds):
'''
Return a synchronization wrapper for a RawArray
'''
lock = kwds.pop('lock', None)
if kwds:
raise ValueError('unrecognized keyword argument(s): %s' % kwds.keys())
obj = RawArray(typecode_or_type, size_or_initializer)
if lock is False:
return obj
if lock in (True, None):
lock = RLock()
if not hasattr(lock, 'acquire'):
raise AttributeError("'%r' has no method 'acquire'" % lock)
return synchronized(obj, lock)
示例7: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def __init__(self, obj, lock=None):
self._obj = obj
self._lock = lock or RLock()
self.acquire = self._lock.acquire
self.release = self._lock.release
示例8: _start_io_tracker
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def _start_io_tracker():
import multiprocessing
global _track_io
global _io_tracker_manager
global _io_tracker_sync
global _write_count
global _read_count
_io_tracker_manager = multiprocessing.Manager()
_io_tracker_sync = multiprocessing.RLock()
_write_count = _io_tracker_manager.Value('I', 0, lock=False)
_read_count = _io_tracker_manager.Value('I', 0, lock=False)
_track_io = True
示例9: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def __init__(self, io_):
self.io = io_
self._lock = multiprocessing.RLock()
self._hook_called = multiprocessing.Value(ctypes.c_int, 0, lock=False)
self._last_caller_pid = multiprocessing.Value(
ctypes.c_int, -1, lock=False)
示例10: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def __init__(self) -> None:
self._hostResolvers = []
# python dict structure is atomic for primitive actions. Need to be checked
self._local_actor_refs = {}
self._sequence_id = 0
self._address = "nonhost"
self._lock = RLock()
示例11: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def __init__(self, log_client, heartbeat_interval, consumer_group_time_out):
super(ConsumerHeatBeat, self).__init__()
self.log_client = log_client
self.heartbeat_interval = heartbeat_interval
self.mheld_shards = []
self.mheart_shards = []
self.shut_down_flag = False
self.lock = RLock()
self.last_hearbeat_successed_unixtime = time.time()
self.consumer_group_time_out = consumer_group_time_out
self.logger = HeartBeatLoggerAdapter(
logging.getLogger(__name__), {"heart_beat": self})
示例12: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def __init__(self, loghub_client_adapter, consumer_name, shard_id):
self.consumer_group_client = loghub_client_adapter
self.consumer_name = consumer_name
self.shard_id = shard_id
self.last_check_time = time.time()
self.cursor = ''
self.temp_check_point = ''
self.last_persistent_checkpoint = ''
self.default_flush_check_point_interval = 60
self.lock = RLock()
示例13: create_mp_lock
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def create_mp_lock(cls, name, is_rlock):
if not hasattr(cls, name):
try:
if is_rlock:
setattr(cls, name, mp.RLock()) # multiprocessing lock
else:
setattr(cls, name, mp.Lock()) # multiprocessing lock
except ImportError: # pragma: no cover
setattr(cls, name, None)
except OSError: # pragma: no cover
setattr(cls, name, None)
示例14: create_th_lock
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def create_th_lock(cls, name, is_rlock):
if not hasattr(cls, name):
try:
if is_rlock:
setattr(cls, name, th.RLock()) # thread lock
else:
setattr(cls, name, th.Lock()) # thread lock
except OSError: # pragma: no cover
setattr(cls, name, None)
示例15: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import RLock [as 別名]
def __init__(self, directory, **kwargs):
"""
:param directory: root dir for storage
"""
super(FileSystemResourceAPI, self).__init__(**kwargs)
self.directory = directory
self.base_path = os.path.join(self.directory, self.name)
self._join_path = partial(os.path.join, self.base_path)
self._lock = RLock()