reloader.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:uzdevsbot 作者: Uzbek-Developers 项目源码 文件源码
def run_with_reloader(loop, coroutine, cleanup=None, *args, **kwargs):
    """ Run coroutine with reloader """

    clear_screen()
    print("??  Running in debug mode with live reloading")
    print("    (don't forget to disable it for production)")

    # Create watcher
    handler = Handler(loop)
    watcher = Observer()

    # Setup
    path = realpath(os.getcwd())
    watcher.schedule(handler, path=path, recursive=True)
    watcher.start()

    print("    (watching {})".format(path))

    # Run watcher and coroutine together
    done, pending = await asyncio.wait([coroutine, handler.changed],
                                       return_when=asyncio.FIRST_COMPLETED)

    # Cleanup
    cleanup and cleanup()
    watcher.stop()

    for fut in done:
        # If change event, then reload
        if isinstance(fut.result(), Event):
            print("Reloading...")
            reload()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号