本文整理汇总了Python中twisted.internet.task.LoopingCall.cancel方法的典型用法代码示例。如果您正苦于以下问题:Python LoopingCall.cancel方法的具体用法?Python LoopingCall.cancel怎么用?Python LoopingCall.cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.task.LoopingCall
的用法示例。
在下文中一共展示了LoopingCall.cancel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loops
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import cancel [as 别名]
class Room:
"""A room is a conference. Everyone in the room hears everyone else
(well, kinda)
"""
# Theory of operation. Rather than rely on the individual sources
# timer loops (which would be, well, horrid), we trigger off our
# own timer.
# This means we don't have to worry about the end systems not
# contributing during a window.
_open = False
def __init__(self, name, MaxSpeakers=4):
self._name = name
self._members = Set()
self._audioOut = {}
self._audioOutDefault = ''
self._maxSpeakers = MaxSpeakers
self.start()
def start(self):
self._audioCalcLoop = LoopingCall(self.mixAudio)
self._audioCalcLoop.start(0.020)
self._open = True
def getName(self):
return self._name
def __repr__(self):
if self._open:
o = ''
else:
o = ' (closed)'
return "<ConferenceRoom %s%s with %d members>"%(self._name, o,
len(self._members))
def shutdown(self):
if hasattr(self._audioCalcLoop, 'cancel'):
self._audioCalcLoop.cancel()
else:
self._audioCalcLoop.stop()
# XXX close down any running sources!
self._members = Set()
del self._audioOut
self._open = False
removeRoom(self._name)
def addMember(self, confsource):
self._members.add(confsource)
if CONFDEBUG:
print "added", confsource, "to room", self
if not self._open:
self.start()
def removeMember(self, confsource):
if len(self._members) and confsource in self._members:
self._members.remove(confsource)
if CONFDEBUG:
print "removed", confsource, "from", self
else:
raise ConferenceMemberNotFoundError(confsource)
if not len(self._members):
if CONFDEBUG:
print "No members left, shutting down"
self.shutdown()
def isMember(self, confsource):
return confsource in self._members
def isOpen(self):
return self._open
def memberCount(self):
return len(self._members)
def readAudio(self, confsource):
if self._open:
return self._audioOut.get(confsource, self._audioOutDefault)
else:
raise ConferenceClosedError()
def mixAudio(self):
# XXX see the comment above about storing a decaying number for the
# volume. For instance, each time round the loop, take the calculated
# volume, and the stored volume, and do something like:
# newStoredVolume = (oldStoredVolume * 0.33) + (thisPacketVolume * 0.66)
import audioop
self._audioOut = {}
if not self._open:
log.msg('mixing closed room %r'%(self,), system='doug')
return
audioIn = {}
for m in self._members:
bytes = m.getAudioForRoom()
if bytes: audioIn[m] = bytes
if CONFDEBUG:
print "room %r has %d members"%(self, len(self._members))
print "got %d samples this time"%len(audioIn)
print "samples: %r"%(audioIn.items(),)
# short-circuit this case
#.........这里部分代码省略.........