Updated code in app.py (from "Getting started") doesn't run until viktor-cli is restarted


I’m trying out VIKTOR for the first time and when I tried the “Create your first app” tutorial, I can’t seem to get the updated code to run when refreshing the app in my developer workspace until I restart “viktor-cli”.

If I understand the tutorial correctly, this should not be required - only to refresh the webpage.

What am I doing wrong?

Everything should be up to date:

viktor-cli.exe: v0.27.3
VIKTOR connector v5.18.2
VIKTOR SDK v13.7.1

Hi pady,

The app should indeed reload once changes in app.py are saved. What IDE are you using? You might need to explicitly use ctrl+s to trigger saving the python file.

Does the CLI print that the app is reloading? You should see something like this upon a reload of the app code:

2023-01-25 17:23:41.009 INFO    : Reloading app...
2023-01-25 17:23:43.901 INFO    : App is ready



I’m using Visual Studio Code and I’m not getting that output in the terminal window:

2023-01-26 09:50:14.078 INFO    : Connecting to platform...
2023-01-26 09:50:15.696 INFO    : Connection is established (Ctrl+click to open in browser): https://cloud.viktor.ai
2023-01-26 09:50:15.697 INFO    : The connection can be closed using Ctrl+C
2023-01-26 09:50:16.697 INFO    : App is ready
2023-01-26 09:50:22.071 INFO    : Job (uid: 106961) received - EntityType: Controller - call: parametrization
2023-01-26 09:50:22.074 INFO    : Job (uid: 106961) completed in 0ms
2023-01-26 09:50:22.363 INFO    : Job (uid: 106962) received - EntityType: Controller - call: beam_visualisation
2023-01-26 09:50:22.787 INFO    : Job (uid: 106962) completed in 421ms

I added a line of code here and saved app.py and refreshed the page:

2023-01-26 09:50:44.837 INFO    : Job (uid: 106963) received - EntityType: Controller - call: parametrization
2023-01-26 09:50:44.845 INFO    : Job (uid: 106963) completed in 0ms
2023-01-26 09:50:45.145 INFO    : Job (uid: 106964) received - EntityType: Controller - call: beam_visualisation
2023-01-26 09:50:45.597 INFO    : Job (uid: 106964) completed in 448ms

Also tried with another browser, but the “new code” doesn’t get executed then either.

Looks like the same issue as described here:

Ok let’s try to narrow it down.

  • If you close the connection to the platform and make a change to your code and restart the CLI does the new code run in that case?
  • What is the change you are making to the code?
  • Could you share the command you use when starting the app? Is it simply viktor-cli start?
  • What is the working directory you execute the command in?
  • Yes, that is how I’ve made it work now. But I’ve changed the code first, closed the connection (Ctrl+C) and restarted it
  • Added print(params) after def beam_visualisation(self, params, **kwargs):
  • Yes, that’s correct: viktor-cli start
  • My working directory is: C:\Users\pady\GitHub\viktor-apps\testing

I run Python 3.9.13 and VS Code 1.74.3

Thanks for the additional information. I now understand what is happening.

The autoreload functionality works by adding the files in your app folder to a file watcher. However, to increase the reloading speed several files are excluded, for example the files in the virtual environment folder or tests. The latter is done by excluding all files and directories that are prefixed with test. Because of the fact that your app folder is called testing the entire folder is not added to the file watcher.

If you change the name of your app folder to something else you should see that the autoreload works as expected.

Thank you for reporting, I will add this to our internal issue tracker to account for this case in future versions of the CLI.

Funny how the simplest things can create such a hazzel :slight_smile:

Thanks for your help!