How to reload a module's function in Python?

后端 未结 8 1809
遥遥无期
遥遥无期 2020-11-28 09:27

Following up on this question regarding reloading a module, how do I reload a specific function from a changed module?

pseudo-code:

from foo import b         


        
8条回答
  •  醉话见心
    2020-11-28 09:58

    Hot reloading is not something you can do in Python reliably without blowing up your head. You literally cannot support reloading without writing code special ways, and trying to write and maintain code that supports reloading with any sanity requires extreme discipline and is too confusing to be worth the effort. Testing such code is no easy task either.

    The solution is to completely restart the Python process when code has changed. It is possible to do this seamlessly, but how depends on your specific problem domain.

提交回复
热议问题