panel icon indicating copy to clipboard operation
panel copied to clipboard

Make `--setup` work with `--num-procs`

Open hoxbro opened this issue 1 year ago • 2 comments

Resolves #6891

Postpone the execution to the start the server.

It needs a bit more thought than what I have given it. This is mostly a POC right now.

# app.py
import panel as pn

pn.pane.Markdown("Hello World").servable()
# background_job.py
from datetime import datetime
import os
import panel as pn

current_time = datetime.now()


def task() -> None:
    """Refresh the data in the database."""
    print(f"Ran task at {datetime.now()} (PID {os.getpid()})")


pn.state.schedule_task(name="load_data", callback=task, at=current_time, period="5s")

Command: panel serve app.py --setup background_job.py --num-procs 2

https://github.com/holoviz/panel/assets/19758978/035e6f2d-269d-49a2-a46a-38669f793a92

hoxbro avatar Jun 11 '24 14:06 hoxbro

Codecov Report

Attention: Patch coverage is 82.69231% with 9 lines in your changes missing coverage. Please review.

Project coverage is 82.23%. Comparing base (4849daf) to head (4a1592f). Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
panel/io/server.py 30.00% 7 Missing :warning:
panel/command/serve.py 66.66% 2 Missing :warning:
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6913    +/-   ##
========================================
  Coverage   82.22%   82.23%            
========================================
  Files         328      330     +2     
  Lines       49269    49379   +110     
========================================
+ Hits        40513    40607    +94     
- Misses       8756     8772    +16     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 11 '24 14:06 codecov[bot]

What's missing here, apart from tests?

Time :upside_down_face: This does not fix the problem observed on older versions of Python. It could, therefore, be that the loading of the file should also be postponed.

hoxbro avatar Jun 24 '24 18:06 hoxbro

This does not fix the problem observed on older versions of Python.

How old are we talking?

philippjfr avatar Aug 01 '24 22:08 philippjfr

Only working with Python 3.12, IIRC.

hoxbro avatar Aug 02 '24 07:08 hoxbro

Would this fix the --warm issue too?

MarcSkovMadsen avatar Aug 27 '24 02:08 MarcSkovMadsen

Would this fix the --warm issue too?

Yes, it should be the case after the changes I made yesterday.

hoxbro avatar Aug 27 '24 07:08 hoxbro

@MarcSkovMadsen @philippjfr - we relied on the setup script to be run before the server starts. This reduces some of the usefuleness of the setup script.

It is also still mentioned in the wiki "--setup SETUP Path to a setup script to run before server starts.". Might want to update the documentation to reflect that this is not supported any longer. Link to the documentation: https://panel.holoviz.org/how_to/server/commandline.html

I would consider this a minor breaking change and would appreciate mentioning it in the changelogs.

instance01 avatar Sep 16 '24 19:09 instance01

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Sep 09 '25 20:09 github-actions[bot]