本文整理汇总了Python中tcf.protocol.isDispatchThread函数的典型用法代码示例。如果您正苦于以下问题:Python isDispatchThread函数的具体用法?Python isDispatchThread怎么用?Python isDispatchThread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isDispatchThread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addEventListener
def addEventListener(self, service, listener):
assert protocol.isDispatchThread()
svc_name = str(service)
listener.svc_name = svc_name
list = self.event_listeners.get(svc_name) or []
list.append(listener)
self.event_listeners[svc_name] = list
示例2: _processQueue
def _processQueue(self):
assert protocol.isDispatchThread()
with self._lock:
for cmd in self._queue:
service, command, args, kwargs = cmd
self._invoke(service, command, *args, **kwargs)
del self._queue[:]
示例3: sendCommand
def sendCommand(self, service, name, args, listener):
assert protocol.isDispatchThread()
if self.state == STATE_OPENING: raise Exception("Channel is waiting for Hello message")
if self.state == STATE_CLOSED: raise Exception("Channel is closed")
msg = Message('C')
msg.service = str(service)
msg.name = name
msg.data = args
channel = self
class CancelableToken(Token):
def __init__(self, listener):
super(CancelableToken, self).__init__(listener=listener)
def cancel(self):
assert protocol.isDispatchThread()
if channel.state != STATE_OPEN: return False
with channel.out_lock:
if msg.is_sent: return False
msg.is_canceled = True
del channel.out_tokens[msg.token.getID()]
return True
token = CancelableToken(listener)
msg.token = token
self.out_tokens[token.getID()] = msg
self.addToOutQueue(msg)
return token
示例4: wait
def wait(self, timeout=None):
assert not protocol.isDispatchThread()
with self._lock:
while self._pending or self._queue:
self._lock.wait(timeout)
if timeout:
break
示例5: sendResult
def sendResult(self, token, results):
assert protocol.isDispatchThread()
if self.state != STATE_OPEN: raise Exception("Channel is closed")
msg = Message('R')
msg.data = results
msg.token = token
self.addToOutQueue(msg)
示例6: __sendCongestionLevel
def __sendCongestionLevel(self):
self.local_congestion_cnt += 1
if self.local_congestion_cnt < 8: return
self.local_congestion_cnt = 0
if self.state != STATE_OPEN: return
timeVal = int(time.time() * 1000)
if timeVal - self.local_congestion_time < 500: return
assert protocol.isDispatchThread()
level = protocol.getCongestionLevel()
if level == self.local_congestion_level: return
i = (level - self.local_congestion_level) / 8
if i != 0: level = self.local_congestion_level + i
self.local_congestion_time = timeVal
with self.out_lock:
msg = None
if self.out_queue:
msg = self.out_queue[0]
if msg is None or msg.type != 'F':
msg = Message('F')
self.out_queue.insert(0, msg)
self.out_lock.notify()
data = "%i\0" % self.local_congestion_level
msg.data = data
msg.trace = self.trace_listeners
self.local_congestion_level = level
示例7: getRemoteService
def getRemoteService(self, cls_or_name):
assert protocol.isDispatchThread()
assert self.state != STATE_OPENING
if type(cls_or_name) == types.StringType:
return self.remote_service_by_name.get(cls_or_name)
else:
return self.remote_service_by_class.get(cls_or_name)
示例8: getData
def getData(self):
"""
@return cached data object.
Note: It is prohibited to call this method when cache is not valid.
"""
assert protocol.isDispatchThread()
assert self.__valid
return self.__data
示例9: cancel
def cancel(self):
if not protocol.isDispatchThread():
protocol.invokeLater(self.cancel)
return
with self._lock:
for cmd in self._pending.values():
cmd.token.cancel()
del self._queue[:]
示例10: dispose
def dispose(self):
assert protocol.isDispatchThread()
id = self.getID()
assert id
peers = protocol.getLocator().getPeers()
assert peers.get(id) == self
del peers[id]
self.sendPeerRemovedEvent()
示例11: cancel
def cancel(self):
assert protocol.isDispatchThread()
if channel.state != STATE_OPEN: return False
with channel.out_lock:
if msg.is_sent: return False
msg.is_canceled = True
del channel.out_tokens[msg.token.getID()]
return True
示例12: terminate
def terminate(self, error):
assert protocol.isDispatchThread()
if self.state == STATE_CLOSED: return
try:
self.__sendEndOfStream(500)
except Exception as x:
if not error: error = x
self._close(error)
示例13: close
def close(self):
assert protocol.isDispatchThread()
if self.state == STATE_CLOSED: return
try:
self.__sendEndOfStream(10000)
self._close(None)
except Exception as x:
self._close(x)
示例14: sendEvent
def sendEvent(self, service, name, args):
assert protocol.isDispatchThread()
if not (self.state == STATE_OPEN or self.state == STATE_OPENING and isinstance(service, locator.LocatorService)):
raise Exception("Channel is closed")
msg = Message('E')
msg.service = str(service)
msg.name = name
msg.data = args
self.addToOutQueue(msg)
示例15: cancel
def cancel(self):
assert protocol.isDispatchThread()
with self._lock:
if self.isDone(): return False
self.__canceled = True
self.__error = Exception("Canceled")
if self.__channel:
self.__channel.removeChannelListener(self.__channel_listener)
self._lock.notifyAll()
return True