• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python threading.Lock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mpx.lib.threading.Lock的典型用法代码示例。如果您正苦于以下问题:Python Lock类的具体用法?Python Lock怎么用?Python Lock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Lock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:mcruse,项目名称:monotone,代码行数:34,代码来源:gateway.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:30,代码来源:__init__.py


示例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()                 
开发者ID:mcruse,项目名称:monotone,代码行数:27,代码来源:auto_discovered_node.py


示例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__()
开发者ID:mcruse,项目名称:monotone,代码行数:9,代码来源:rt_device.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:9,代码来源:schedule.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:10,代码来源:trigger.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:11,代码来源:energywise_api.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:52,代码来源:canbus.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:13,代码来源:socketmap.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:15,代码来源:__init__.py


示例11: setUp

 def setUp(self):
     DefaultTestFixture.setUp(self)
     self.lock = Lock()
     self.pool = ThreadPool(3)
     self.queue = Queue()
     self.simple_action_counter = 0
     return
开发者ID:mcruse,项目名称:monotone,代码行数:7,代码来源:_test_case_thread_pool.py


示例12: __init__

 def __init__(self):
     super(DRASManager, self).__init__()
     self.__scheduled = None
     self.__observers = {}
     self.__lock = Lock()
     self.running = 0
     return
开发者ID:mcruse,项目名称:monotone,代码行数:7,代码来源:client.py


示例13: __init__

 def __init__(self, port):
     self.lock = Lock()    
     self.port = port
     self.units = {}
     self.connected = 0
     if not port.is_open():
         port.open()
开发者ID:mcruse,项目名称:monotone,代码行数:7,代码来源:line_handler.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:7,代码来源:_test_case_subscription_manager.py


示例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
开发者ID:mcruse,项目名称:monotone,代码行数:7,代码来源:ewebconnect.py


示例16: __init__

 def __init__(self):
     self.observers = {}
     self.data = None
     self.running = False
     self._ob_lock = Lock()
     super(BrivoDispatcher, self).__init__()
     return
开发者ID:mcruse,项目名称:monotone,代码行数:7,代码来源:dispatcher.py


示例17: TunnelManager

class TunnelManager(CompositeNode):
    def __init__(self, *args):
        global PTY_DEVS
        self._lock = Lock()
        self._pty_devs = []
        self._ptys_allocated = 0
        module_lock.acquire()
        try:
            if PTY_DEVS is None:
                PTY_DEVS = []
                for major in 'wxyz':
                    for minor in '0123456789abcdef':
                        PTY_DEVS.append('/dev/pty%s%s' % (major, minor))
        finally:
            module_lock.release()
            
    def configure(self, config):
        # vcp_limit is a "hidden" attribute.
        set_attribute(self, 'vcp_limit', 64, config, int)
        CompositeNode.configure(self, config)
        
    def configuration(self):
        config = CompositeNode.configuration(self)
        get_attribute(self, 'vcp_limit', config, str)
        return config
    
    ##
    # Allocate a pseudo-terminal for use by the Port object.
    #
    # @return a string, ie. /dev/ptyr0. 
    def get_pty(self):
        global PTY_DEVS
        self._lock.acquire()
        try:
            while len(PTY_DEVS):
                pty = PTY_DEVS.pop()
                try:
                    # confirm that the pty is accessible.
                    fd = open(pty)
                    fd.close()
                    self._ptys_allocated += 1
                    return pty
                except:
                    pass
            raise EResourceError
        finally:
            self._lock.release()
开发者ID:mcruse,项目名称:monotone,代码行数:47,代码来源:vcp.py


示例18: __init__

 def __init__(self):
     self._link = None #get 'actual' node
     self.link = None
     self._proxy_get = None #set to actual's preferred get method
     self._proxy_set = None
     self._proxy_start_exception = None
     self._proxy_sid = None
     self.proxy_direction = GET_ONLY #direction subscription "pushes" the data
     self._proxy_active_source = None
     self._proxy_active_destination = None
     self._proxy_active_lock = Lock()
     self._proxy_active_thread_lock = Lock()
     self._proxy_active_event = None
     self._proxy_trigger_counter = 0
     self._retry_win_high = 30
     EventConsumerMixin.__init__(self, self.change_of_value)
     self.debug = debug
开发者ID:mcruse,项目名称:monotone,代码行数:17,代码来源:proxy.py


示例19: __init__

 def __init__(self):
     self._subscription_lock = Lock()
     self._subscribed = 0
     self._subscribers = {}
     self._last_value = None
     self._last_rcvd = None
     self._decode_indexes = {}
     return
开发者ID:mcruse,项目名称:monotone,代码行数:8,代码来源:http_client.py


示例20: __init__

 def __init__(self, node):
     self.__lock = Lock()
     self.__last_save = {}
     self.max_seq = -1
     self.pending_seqs = []
     self.inprocess_seqs = []
     PersistentDataObject.__init__(self, node, auto_load=True)
     return
开发者ID:mcruse,项目名称:monotone,代码行数:8,代码来源:trap_exporter.py



注:本文中的mpx.lib.threading.Lock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python service.ServiceNode类代码示例发布时间:2022-05-27
下一篇:
Python persistent.PersistentDataObject类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap