Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created March 1, 2020 06:43
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 podhmo/79177b3f203728e93dd8bbe453b24172 to your computer and use it in GitHub Desktop.
Save podhmo/79177b3f203728e93dd8bbe453b24172 to your computer and use it in GitHub Desktop.
from handofcats import as_command, print
@as_command
def run():
print("hello")
print("byebye")
--- 01update_check.py 2020-03-01 15:37:07.000000000 +0900
+++ 02update_check.py 2020-03-01 15:37:22.000000000 +0900
@@ -31,7 +31,8 @@
def main():
async def run():
fut = asyncio.ensure_future(update_check())
- run_main()
+ loop = asyncio.get_event_loop()
+ await loop.run_in_executor(None, run_main)
update_version = await fut
if update_version is not None:
print(f"A new release of gh is available: xxx → {update_version}")
import typing as t
import asyncio
import random
from handofcats import as_command, print
async def update_check() -> t.Awaitable[t.Optional[str]]:
print("-> update_check ...")
await asyncio.sleep(0.5)
print("<- ... update_check")
if random.random() < 0.2:
# update is not found
return None
# update is found
return "0.8.8"
def run_main():
import time
print("do something (main)")
for i in range(6):
print(".")
time.sleep(0.1)
print("ok")
@as_command
def main():
async def run():
fut = asyncio.ensure_future(update_check())
run_main()
update_version = await fut
if update_version is not None:
print(f"A new release of gh is available: xxx → {update_version}")
asyncio.run(run())
import typing as t
import asyncio
import random
from handofcats import as_command, print
async def update_check() -> t.Awaitable[t.Optional[str]]:
print("-> update_check ...")
await asyncio.sleep(0.5)
print("<- ... update_check")
if random.random() < 0.2:
# update is not found
return None
# update is found
return "0.8.8"
def run_main():
import time
print("do something (main)")
for i in range(6):
print(".")
time.sleep(0.1)
print("ok")
@as_command
def main():
async def run():
fut = asyncio.ensure_future(update_check())
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, run_main)
update_version = await fut
if update_version is not None:
print(f"A new release of gh is available: xxx → {update_version}")
asyncio.run(run())
00:
DEBUG=1 python $(shell echo $@*.py)
01:
LOGGING_TIME=relative DEBUG=1 python $(shell echo $@*.py)
02:
LOGGING_TIME=relative DEBUG=1 python $(shell echo $@*.py)
03:
diff -u 01*.py 02*.py > 0102.diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment