当前位置: 首页 > news >正文

移动互联网的终端包括我们大家经常使用的网站网页的优化方法

移动互联网的终端包括我们大家经常使用的,网站网页的优化方法,wordpress移动应用,教做年糕博客网站什么是状态机#xff1f; 关键属性#xff1a; 状态和转换 状态#xff1a; 系统当前状态 转换#xff1a;一种状态到另外一种状态的变化。 转换由触发事件或是条件启动。 状态机-状态图 状态机使用场景#xff1a; 自动售货机 电梯 交通灯 组合锁 停车计时…什么是状态机  关键属性 状态和转换 状态 系统当前状态 转换一种状态到另外一种状态的变化。 转换由触发事件或是条件启动。 状态机-状态图 状态机使用场景  自动售货机  电梯  交通灯   组合锁  停车计时器   使用state_machine 模块创建状态机第一步使用acts_as_state_machine装饰器 acts_as_state_machine class Process: initial 属性值设置为 True created State(initialTrue) waiting State() running State() terminated State() blocked State() swapped_out_waiting State() swapped_out_blocked State() 定义转换。在 state_machine 模块中转换是 Event 类的一个实例。我们使用 参数 from_states 和 to_state 定义可能的转换。   wait Event(from_states(created, running, blocked, swapped_out_waiting), to_statewaiting) run Event(from_stateswaiting, to_staterunning) terminate Event(from_statesrunning, to_stateterminated) block Event(from_states(running,swapped_out_blocked), to_stateblocked) swap_wait Event(from_stateswaiting, to_stateswapped_out_waiting) swap_block Event(from_statesblocked, to_stateswapped_out_blocked) from_states 可以是单个状态也可以是一组状态元组。 state_machine 模块为我们 提供了 before 和 after 装饰器二者可以分别用于在转换发生之前或之后执行操作。你可以 想象在系统中更新一些对象或者向某人发送电子邮件或通知。在本例中操作仅限于打印关于 进程状态更改的信息。 transition() 函数它接受三个参数  process Process 的一个实例  event Event 的一个实例 wait 、 run 、 terminate 等  event_name 事件的名称。 执行事件时出错则输出事件的名称。 下面是 transition() 函数的代码   def transition(process, event, event_name): try: event() except InvalidStateTransition as err: print(fError: transition of {process.name} from {process.current_state} to {event_name} failed) state_info() 函数显示进程当前激活状态的一些基本信息。  def state_info(process): print(fstate of {process.name}: {process.current_state}) 在 main() 函数的开头我们定义了一些字符串常量它们被作为 event_name 传递。   def main(): RUNNING running WAITING waiting BLOCKED blocked TERMINATED terminated 创建两个 Process 实例并展示它们的初始状态信息。  p1, p2 Process(process1), Process(process2) [state_info(p) for p in (p1, p2)] 允许的转换应该与 状态图相关。例如应该可以从一个运行状态切换到一个阻塞状态但是不应该从一个阻塞状态 切换到一个运行状态。 from state_machine import (State,Event,acts_as_state_machine,after,before,InvalidStateTransition)acts_as_state_machine class Process:createdState(initialTrue) # 创建状态waitingState() #等待状态runningState()# 运行状态terminatedState()# 停止状态blockedState() # 阻塞swapper_out_waitingState()#swapper_out_blockedState()# 等待状态 转入的状态from_states 目标状态 to_statewaitEvent(from_states(created,running,blocked,swapper_out_waiting),to_statewaiting)runEvent(from_stateswaiting,to_staterunning)terminateEvent(from_statesrunning,to_stateterminated)blockEvent(from_states(running,swapper_out_blocked),to_stateblocked)swap_waitEvent(from_stateswaiting,to_stateswapper_out_waiting)swap_blockEvent(from_statesblocked,to_stateswapper_out_blocked)def __init__(self,name):self.namenameafter(wait)def wait_info(self):print(f{self.name} entered waiting mode)after(run)def run_info(self):print(f{self.name} is running)before(ternimate)def terminate_info(self):print(f{self.name} terminated)after(block)def block_info(self):print(f{self.name} is blocked)after(swap_wait)def swap_wait_info(self):print(f{self.name} is swapped out and waiting)after(swap_block)def swap_block_info(self):print(f{self.name} is swapped out and blocked)after(block)def block_info(self):print(f{self.name} is blocked)after(swap_wait)def swap_wait_info(self):print(f{self.name} is swapped out and waiting)after(swap_block)def swap_block_info(self):print(f{self.name} is swapped out and blocked)def transition(process,event,event_name):try:event()except InvalidStateTransition as err:print(fError: transaction of {process.name} from {process.current_state} to {event_name} failed)# 显示信息def state_info(process):print(fstate of {process.name}:{process.current_state})def main():RUNNINGrunningWAITINGwaitingBLOCKEDblockedTERMINATEDterminatedp1,p2Process(process1),Process(process2)[state_info(p) for p in (p1,p2)]print(-------1----------)transition(p1,p1.wait,WAITING)transition(p2,p2.terminate,TERMINATED)[state_info(p) for p in (p1,p2)]print(------2----------)transition(p1,p1.run,RUNNING)transition(p2,p2.wait,WAITING)[state_info(p) for p in (p1, p2)]print(------3----------)transition(p2, p2.run, RUNNING)[state_info(p) for p in (p1, p2)]print(------4----------)[transition(p,p.block,BLOCKED) for p in (p1,p2)][state_info(p) for p in (p1, p2)]print(------5----------)[transition(p, p.terminate, TERMINATED) for p in (p1, p2)]if __name____main__:main()state of process1:created state of process2:created -------1---------- process1 entered waiting mode Error: transaction of process2 from created to terminated failed state of process1:waiting state of process2:created ------2---------- process1 is running process2 entered waiting mode state of process1:running state of process2:waiting ------3---------- process2 is running state of process1:running state of process2:running ------4---------- process1 is blocked process1 is blocked process2 is blocked process2 is blocked state of process1:blocked state of process2:blocked ------5---------- Error: transaction of process1 from blocked to terminated failed Error: transaction of process2 from blocked to terminated failed
http://www.hkea.cn/news/14332414/

相关文章:

  • 为什么进行网站备案优化建站seo门户
  • 网站建设及 维护曹县做网站
  • 代做毕业设计找哪个网站好网页设计有什么证书
  • 本网站三天换一次域名网站开发税率税种
  • 网站建设销售工作怎么样男生和男生做污的视频网站
  • 做外贸自己开公司网站wordpress 添加用户
  • 网站源码有什么用曲阜公司网站建设价格
  • 官方网站开发公司小米的网站设计
  • 网站建设氺金手指排名15怎么做网站内容
  • 环保材料东莞网站建设代理企业网站备案
  • 自己做钓鱼网站腾讯云域名管理
  • 企业申报网站哪家网站建设
  • 长春网站建设seo政务网站建设论文
  • 酒店网站素材做证书的网站
  • 绿色企业网站源码外贸网站海外推广3个必去网站
  • 建设网站东莞公司全渠道分销零售平台
  • 福州建设工程质量监督网站wordpress更改页脚社交图标
  • 网站建设的论文的参考文献青白江区建设局网站
  • 电子商务开发公司seo基础知识培训
  • php网站开发实践指南怎样做网站挣钱
  • ai建筑设计平台宁波网站优化平台
  • 广州做网站一般要多少钱常州seo网络推广
  • 最常用的网站开发工具找工作哪个网站好招聘信息
  • wordpress如何开启redis江苏怎么做网站排名优化
  • 网站类型分类有哪些北京网站制作平台
  • 网站设计首页动态效果怎么做360浏览器直接进入网站
  • 嘉兴建设中心小学网站信誉好的做网站
  • 红色专题网站首页模板网站设计就业前景如何
  • 免费下载app泰安关键词优化
  • 之梦系统怎么修改网站标头图片高端网络建站