本文整理汇总了Python中transitions.Machine.to_unlinked方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.to_unlinked方法的具体用法?Python Machine.to_unlinked怎么用?Python Machine.to_unlinked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transitions.Machine
的用法示例。
在下文中一共展示了Machine.to_unlinked方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Connection
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import to_unlinked [as 别名]
class Connection(IdentifiableObject):
states = ['new', 'linked', 'unlinked']
def __init__(self, name=None, capacity=1):
super().__init__()
self.logger = logging.getLogger(__name__)
self.id = uuid4()
self.state = Machine(states=Connection.states, initial='new')
if name:
self.name = name
else:
self.name = self._instance_name
self.capacity = capacity
self.packet_queue = asyncio.Queue(self.capacity)
self.source = None
self.target = None
def __eq__(self, other):
return self.id == other.id
def link(self, source: OutputPort, target: InputPort):
self.source = source
self.target = target
source.add_connection(self)
target.add_connection(self)
self.logger.debug("Linked created: %s:%s -> %s:%s" % (source.component.name, source.name, target.component.name, target.name))
self.state.to_linked()
def unlink(self):
self.logger.debug("Linked removed: %s:%s -> %s:%s" % (self.source.component.name, self.source.name, self.target.component.name, self.target.name))
self.source = None
self.target = None
# Todo: remove connection from source and target
self.state.to_unlinked()
async def put_packet(self, packet):
await self.packet_queue.put(packet)
async def get_packet(self):
packet = await self.packet_queue.get()
return packet