예제 #1
0
 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}")
예제 #2
0
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"
예제 #3
0
def update_check() -> t.Optional[str]:
    print("-> update_check ...")
    time.sleep(0.5)
    print("<- ... update_check")

    if random.random() < 0.2:
        # update is not found
        return None

    # update is found
    return "0.8.8"
예제 #4
0
    async def run():
        fut = asyncio.ensure_future(update_check())

        print("do something (main)")
        for i in range(6):
            print(".")
            sys.stdout.flush()
            await asyncio.sleep(0.1)
        print("ok")

        update_version = await fut
        if update_version is not None:
            print(f"A new release of gh is available: xxx → {update_version}")
예제 #5
0
def run_main():
    import time

    print("do something (main)")
    for i in range(6):
        print(".")
        time.sleep(0.1)
    print("ok")
예제 #6
0
def main():
    update_version = None

    def _check():
        nonlocal update_version
        update_version = update_check()

    th = threading.Thread(target=_check, daemon=True)
    th.start()

    print("do something (main)")
    for i in range(6):
        print(".")
        sys.stdout.flush()
        time.sleep(0.1)
    print("ok")

    th.join()
    if update_version is not None:
        print(f"A new release of gh is available: xxx → {update_version}")
예제 #7
0
 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}")
예제 #8
0
def foo():
    print("hello")
    print("byebye")