18

Hot-swapping Python 3 code

 4 years ago
source link: https://github.com/say4n/hotreload
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

feMzmab.png!web

hotreload.py

hot reload your python code!

Run any arbitrary python script every time the code changes in the file.

installation

Get the package from PyPI with pip3 install hotreload .

usage

Say you have script ( script.py ) that you want to run every time the code changes in that file.

To do that, it is as simple as doing this:

import time
import logging
from hotreload import Loader


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    script = Loader("script.py")

    while True:
        # Check if script has been modified since last poll.
        if script.has_changed():
            # Execute a function from script if it has been modified.
            script.main()

        time.sleep(1)

author

Sayan Goswami © 2020


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK