Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (1.6k points)

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 bee.py has changed:

    unimport bee  <-- How do I do this?

    import bee

    my_bee = bee.Bee()

1 Answer

0 votes
by (25.1k points)

It looks like you want to want to reload an already loaded module. You can use the reload function from the importlib library.

E.g:

import foo

from importlib import reload

while True:

    if is_changed(foo):

        foo = reload(foo)

please note that the above code will work only for python 3.4 and above for python 3.0 to 3.3 import imp instead of import importlib

Related questions

0 votes
4 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...