本文整理汇总了Python中mpx.lib.threading.Lock类的典型用法代码示例。如果您正苦于以下问题:Python Lock类的具体用法?Python Lock怎么用?Python Lock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: XCommandIface
class XCommandIface(TcpConnection):
def __init__(self, port, host, debug):
self.__lock = Lock() # lock serializes XCommandIface messaging
super(XCommandIface, self).__init__(port, host, debug)
return
def write(self, method_name, params):
self.__lock.acquire()
try:
if not self.connection_ok():
self.open_connection()
# marshal data from param tuple
data = xmlrpclib.dumps(tuple([params]), method_name)
#payload is 4 byte, little endian, field representing the length of
#the xml data, followed by the data
msg = struct.pack('<I', len(data)) + data
try:
self._s.send(msg)
except:
msglog.log('Adura', ERR, 'Error writing to XCommand socket.')
raise EConnectionError
rslt = self.read()
finally:
self.close_connection()
self.__lock.release()
def read(self):
# leading 4 bytes indicates length of xml-rpc response payload
read_len = struct.unpack('<I', self._s.recv(4, timeout=SOCK_OP_TIMEOUT))[0]
# retreive and marshall the results. If the xml-rpc packet represents a
# fault condition, loads() raises a Fault exception. @fixme - need a
# better understanding of their normal result structure
rslt = xmlrpclib.loads(self._s.recv(read_len, timeout=SOCK_OP_TIMEOUT))[0]
return rslt
示例2: __init__
def __init__(self):
ConfigurableNode.__init__(self)
self._url = 'unknown'
self._poll_event = None
self._period = 0.2
# Pre-load attributes.
self.off_text = "Off"
self.on_text = "On"
self.auto_text = "Auto"
self.reverse_output = 0
self.output = REQUIRED
self.input = REQUIRED
self.period = self._period
self.asyncOK = 1
self.state = 2
self.debug = 0
self.__running = False
self._init_debug()
self.OFF = EnumeratedValue(0, self.off_text)
self.ON = EnumeratedValue(1, self.on_text)
self.AUTO = EnumeratedValue(2, self.auto_text)
self._NORMAL = 0
self._SAFETY = 1
self._output_state = self._NORMAL
self._output_lock = Lock()
self._changes_at = 0
self._waiting_value = None
self._value = None
self._lock = Lock()
return
示例3: __init__
class _Lock:
def __init__(self):
self._minutes = 0
self._lock = Lock()
self._scheduled = None
self._stack = None
def acquire(self,blocking=0):
value = self._lock.acquire(blocking)
self._stack = traceback.extract_stack()
self._schedule_print()
return value
def release(self):
try:
if self._scheduled:
self._scheduled.cancel()
finally:
self._lock.release()
def locked(self):
return self._lock.locked()
def _schedule_print(self):
self._scheduled = scheduler.after(60,self._print,(self._stack,))
def _print(self,stack):
self._minutes += 1
print 'Lock acquired: %s min' % self._minutes
print string.join(traceback.format_list(stack))
if self.locked():
self._schedule_print()
示例4: __init__
def __init__(self):
self.rt_request_obj = device.real_time_value_req()
self.rt_response_obj = device.real_time_value_res()
self.cr_request_obj = device.control_relay_req()
self.cr_response_obj = device.control_relay_res()
self.rt_lock = Lock()
self.cr_lock = Lock()
self.rt_last_updated = 0
super(DeviceRT, self).__init__()
示例5: __init__
def __init__(self):
CompositeNode.__init__(self)
EventProducerMixin.__init__(self)
self._schedule_lock = Lock()
self._schedule_condition = Condition()
self._value_lock = Lock()
self._value_condition = Condition()
self.__schedule = None
self.__value = None
示例6: __init__
def __init__(self):
Calculator.__init__(self)
EventProducerMixin.__init__(self)
self._state = self.INITIALIZING
self._current_id = None
self._scheduled = None
self._state_lock = Lock()
self._schedule_lock = Lock()
self.require_acknowledge = 0
return
示例7: __init__
def __init__(self):
self._cpex_lock=RLock() # cpex switch list lock, used for setting/getting the "primary" cpex switch.
self._cache_lock=Lock() # domain value cache lock.
self._cpex_switch_map_lock = Lock() # lock for cpex switches cache data structure
self._cache_value=None
self._cache_time=0
self._cpex_switch_map_cache=SwitchMap({})
self._cpex_switch_map_time=0
self.ttl=30
self._reinit()
return
示例8: CANBus
class CANBus(ARMNode, AutoDiscoveredNode):
def __init__(self):
ARMNode.__init__(self)
AutoDiscoveredNode.__init__(self)
self._lock = Lock()
self.conversion_list = {}
self._queue = Queue()
self.debug = 0
self.running = 0
self._start_called = 0
self.devices = ''
self.device_addresses = []
self._been_discovered = 0
def lock(self):
self._lock.acquire()
def unlock(self):
self._lock.release()
##
# @see node.ARMNode#configure
#
def configure(self,config):
ARMNode.configure(self,config)
def configuration(self):
config = ARMNode.configuration(self)
#get_attribute(self, 'devices', config)
return config
##
# start temperature conversions
#
def start(self):
ARMNode.start(self)
self.running = 0
def stop(self):
self.running = 0
##
# discover and create object instances
#
def _discover_children(self, force=0):
if force:
self._been_discovered = 0
if self.running == 1 and not self._been_discovered:
pass
return self._nascent_children
示例9: ExplicitSocketMap
class ExplicitSocketMap(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
self.__lock = Lock()
self.__notifier = SocketMapNotifier(self)
return
def wakeup(self):
self.__lock.acquire()
try:
self.__notifier.wakeup()
finally:
self.__lock.release()
return
示例10: UniqueID
class UniqueID(PersistentDataObject):
def __init__(self,node):
self._lock = Lock()
self.id = 0
PersistentDataObject.__init__(self,node)
self.load()
def allocate_id(self):
self._lock.acquire()
try:
id = self.id
self.id += 1
self.save('id')
finally:
self._lock.release()
return id
示例11: setUp
def setUp(self):
DefaultTestFixture.setUp(self)
self.lock = Lock()
self.pool = ThreadPool(3)
self.queue = Queue()
self.simple_action_counter = 0
return
示例12: __init__
def __init__(self):
super(DRASManager, self).__init__()
self.__scheduled = None
self.__observers = {}
self.__lock = Lock()
self.running = 0
return
示例13: __init__
def __init__(self, port):
self.lock = Lock()
self.port = port
self.units = {}
self.connected = 0
if not port.is_open():
port.open()
示例14: __init__
def __init__(self, *args, **kw):
DefaultTestFixture.__init__(self, *args,**kw)
EventConsumerMixin.__init__(self, self.change_of_value)
self.__event_lock = Lock()
self.__event_updated_values = {}
self._cov_counter = 0
return
示例15: __init__
def __init__(self):
self.__alarm_queue = Queue()
self.__current_thread = None
self.__lock = Lock()
self._init_default_attribute_values()
Client.__init__(self)
return