Skip to content

Instantly share code, notes, and snippets.

@gottadiveintopython
Last active December 22, 2019 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gottadiveintopython/f8faea8231f86d74b5e56c459232a986 to your computer and use it in GitHub Desktop.
Save gottadiveintopython/f8faea8231f86d74b5e56c459232a986 to your computer and use it in GitHub Desktop.
Qiita記事 callback関数に渡される引数も利用
from kivy.clock import Clock
from kivy.app import App
from kivy.uix.widget import Widget
def start_gen(gen):
def step_gen(dt):
try:
Clock.schedule_once(step_gen, gen.send(dt))
except StopIteration:
pass
step_gen(None)
def some_task():
print('処理1')
s = yield 1
print(f"1秒の停止を求めたところ、実際には{s:.03f}秒停止した")
print('処理2')
s = yield 2
print(f"2秒の停止を求めたところ、実際には{s:.03f}秒停止した")
print('処理3')
class SampleApp(App):
def build(self):
return Widget()
def on_start(self):
start_gen(some_task())
if __name__ == '__main__':
SampleApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment