Exemple #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}")
Exemple #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"
Exemple #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"
Exemple #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}")
Exemple #5
0
def run_main():
    import time

    print("do something (main)")
    for i in range(6):
        print(".")
        time.sleep(0.1)
    print("ok")
Exemple #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}")
Exemple #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}")
Exemple #8
0
def foo():
    print("hello")
    print("byebye")