Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...