0

I've decided to make a simple Telegram Bot in order to learn a bit of Python. I have a main.py that imports and executes another file

#!/usr/bin/env python
import butlerr

if __name__ == '__main__':
    butlerr.main()

I run that file

> python src/main.py

But if I make a change in butlerr.py, that's not reflected in the running app. I imagine I won't see changes in a running app. It works if I stop the command and re-run it, obviously.

I figure that's probably not the way to develop. Is there a more seamless way to make changes and see them immediately? I saw a blog post where they create like a web server, but I think that doesn't work on my case.

I closed a question I previously made cause I thought it was a docker issue, but it was not.

3
  • 2
    It generally doesn't make sense to swap modules in a running process. The objects that were already created have obviously been created with the old version of a module, so they won't be compatible with a new version of the module. For example, butlerr.main() would have already been called and be running – the effect of swapping it with a new version would be undefined. Commented Jan 27, 2022 at 10:22
  • 1
    Can you look at this article, maybe it works for you; towardsdatascience.com/… Commented Jan 27, 2022 at 10:24
  • 1
    Then how's the development cycle? I mean, I want to code and then see the changes when talking to the bot. Right now, I have to make the change, stop the running process, re-run it, then talk to the bot again. (Sorry if the question is stupid, today's literally the first day I'm writing a line of python) Commented Jan 27, 2022 at 10:25

1 Answer 1

1

What you are looking for is called hot-reloading. every famous python framework has the hot-reloading option ( so you can turn it on and off )

first check if your package has this feature or not.

Then if it did not have hot-reloading option, you can run your python app using this package

Sign up to request clarification or add additional context in comments.

1 Comment

That worked perfectly! Thank you very much. github.com/JorgeAnzola/butlerr/blob/master/Dockerfile#L11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.