Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/how_to/callbacks/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The `pn.state.schedule_task` functionality allows scheduling global tasks at cer

The different contexts in which global tasks and periodic callbacks run also has implications on how they should be scheduled. Scheduled task **must not** be declared in the application code itself, i.e. if you are serving `panel serve app.py` the callback you are scheduling must not be declared in the `app.py`. It must be defined in an external module or in a separate script declared as part of the `panel serve` invocation using the `--setup` commandline argument.

When using `panel serve` provide a Python setup script with `--setup <script.py>`; do not wrap setup code in `if __name__ == "__main__":` and avoid blocking loops — use `pn.state.schedule_task` for periodic work.

Scheduling using `pn.state.schedule_task` is idempotent, i.e. if a callback has already been scheduled under the same name subsequent calls will have no effect. By default the starting time is immediate but may be overridden with the `at` keyword argument. The period may be declared using the `period` argument or a cron expression (which requires the `croniter` library). Note that the `at` time should be in local time but if a callable is provided it must return a UTC time. If `croniter` is installed a `cron` expression can be provided using the `cron` argument.

Here is a simple example of a task scheduled at a fixed interval:
Expand Down
3 changes: 1 addition & 2 deletions doc/tutorials/intermediate/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,13 @@ options:
--autoreload Whether to autoreload source when script changes.
--num-threads NUM_THREADS
Whether to start a thread pool which events are dispatched to.
--setup SETUP Path to a setup script to run before server starts.
--setup SETUP Path to a Python setup script to run before server starts.
--liveness Whether to add a liveness endpoint.
--liveness-endpoint LIVENESS_ENDPOINT
The endpoint for the liveness API.
--reuse-sessions Whether to reuse sessions when serving the initial request.
--global-loading-spinner
Whether to add a global loading spinner to the application(s).
```

## Recap

Expand Down
Loading