How do I unload (reload) a Python module?

后端 未结 20 2356
轮回少年
轮回少年 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:29

    In Python 3.0–3.3 you would use: imp.reload(module)

    The BDFL has answered this question.

    However, imp was deprecated in 3.4, in favour of importlib (thanks @Stefan!).

    I think, therefore, you’d now use importlib.reload(module), although I’m not sure.

提交回复
热议问题