Servable() runs twice

I cannot understand this behavior and would really appreciate some help.
I have a particular class say my_monitor which have a view function.

When I run the following code:

q = my_monitor().view()
q1 = pn.Row(q2).servable()

The output is as expected. Except that there seems to be 2 “runs” of the my_monitor class… once before starting the panel instance and one after. I have figured this out by having print statement in the class. Can you help understand why this happens?

thank you

Could you provide some detail on the command you’re using to launch the app?

I imagine somewhere in your app, you have .show() and when you use panel serve it executes the servable and show.

Are you seeing the output twice before opening a browser and starting a new session with the app?

I am publishing the script straight from the cmd. with panel serve --show --autoreload
my_monitor is your run of the mill class… with init, a couple of functions, a create_layout amalgamation of pn.rows and pn.columns. I think the issue resides with the class being param… but im not sure. when I run the above command:

  1. the init run (can see from some print statements)
  2. then the dashboard opens in a browser
  3. then the init runs again.

once before and once after :slightly_frowning_face:

I have a guess that the application module is executed first once when you start the application, and then once per each unique session. You could use caching for things you want to run only once. See: Automatically Cache — Panel v1.3.8