前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python asyncio coroutine协程(并行编程 27)

python asyncio coroutine协程(并行编程 27)

作者头像
用户5760343
发布2019-07-30 10:49:06
4440
发布2019-07-30 10:49:06
举报
文章被收录于专栏:sktj

image.png

@asyncio.coroutine yield from State1(xxx)

import asyncio import datetime import time from random import randint

@asyncio.coroutine def StartState(): print("Start State called \n") input_value = randint(0, 1) time.sleep(1) if (input_value == 0): result = yield from State2(input_value) else: result = yield from State1(input_value) print("Resume of the Transition: \nStart State calling " + result)

@asyncio.coroutine def State1(transition_value): outputValue = str(("State 1 with transition value = %s \n" %(transition_value))) input_value = randint(0, 1) time.sleep(1) print("...Evaluating....") if (input_value == 0): result = yield from State3(input_value) else: result = yield from State2(input_value)

代码语言:javascript
复制
result = "State 1 calling " + result
return (outputValue + str(result))

@asyncio.coroutine def State2(transition_value): outputValue = str(("State 2 with transition value = %s \n" %(transition_value))) input_value = randint(0, 1) time.sleep(1) print("...Evaluating....") if (input_value == 0): result = yield from State1(input_value) else: result = yield from State3(input_value)

代码语言:javascript
复制
result = "State 2 calling " + result
return (outputValue + str(result))

@asyncio.coroutine def State3(transition_value): outputValue = str(("State 3 with transition value = %s \n" %(transition_value))) input_value = randint(0, 1) time.sleep(1) print("...Evaluating....") if (input_value == 0): result = yield from State1(input_value) else: result = yield from EndState(input_value)

代码语言:javascript
复制
result = "State 2 calling " + result
return (outputValue + str(result))

@asyncio.coroutine def EndState(transition_value): outputValue = str(("End State with transition value = %s \n" %(transition_value))) print("...Stop Computation...") return (outputValue)

if name == "main": print("Finite State Machine simulation With Asyncio Coroutine") loop = asyncio.get_event_loop() loop.run_until_complete(StartState())

yield from asyncio.sleep(1)

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.07.28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • @asyncio.coroutine yield from State1(xxx)
  • yield from asyncio.sleep(1)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档