How do I unload (reload) a Python module?

后端 未结 20 2438
轮回少年
轮回少年 2020-11-21 05:20

I have a long-running Python server and would like to be able to upgrade a service without restarting the server. What\'s the best way do do this?

if foo.py          


        
20条回答
  •  自闭症患者
    2020-11-21 05:31

    2018-02-01

    1. module foo must be imported successfully in advance.
    2. from importlib import reload, reload(foo)

    31.5. importlib — The implementation of import — Python 3.6.4 documentation

提交回复
热议问题