-
-
Save gottadiveintopython/f8faea8231f86d74b5e56c459232a986 to your computer and use it in GitHub Desktop.
Qiita記事 callback関数に渡される引数も利用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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