Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 5, 2023
1 parent 2fbead0 commit 1e961b8
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion doc/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The Cheat Sheet provides a high-level overview of some of the most important fun
:link: config
:link-type: doc

The `panel.config` provides a way to set high-level configuration options.
The `panel.config` provides a way to set high-level configuration options.
:::

:::{grid-item-card} {octicon}`link;2.5em;sd-mr-1` State
Expand Down
1 change: 1 addition & 0 deletions doc/how_to/apis/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ In this approach we once again define the widgets. Unlike in other approaches we

```{pyodide}
import hvplot.pandas
import panel as pn
from bokeh.sampledata.autompg import autompg
Expand Down
2 changes: 1 addition & 1 deletion doc/how_to/apis/parameterized.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MPGExplorer(param.Parameterized):
@param.depends('x', 'y', 'color') # optional in this case
def plot(self):
return autompg.hvplot.scatter(x, y, c=color, padding=0.1)
return autompg.hvplot.scatter(self.x, self.y, c=self.color, padding=0.1)
explorer = MPGExplorer()
Expand Down
10 changes: 5 additions & 5 deletions doc/how_to/concurrency/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ async def get_img(index):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://picsum.photos/800/300?image={index}") as resp:
return pn.pane.JPG(await resp.read())
pn.Column(widget, pn.bind(get_img, widget))
```

In this example Panel will invoke the function and update the output when the function returns while leaving the process unblocked for the duration of the `aiohttp` request.
In this example Panel will invoke the function and update the output when the function returns while leaving the process unblocked for the duration of the `aiohttp` request.

Similarly you can attach asynchronous callbacks using `.param.watch`:

Expand All @@ -29,11 +29,11 @@ async def update_img(event):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://picsum.photos/800/300?image={event.new}") as resp:
image.object = await resp.read()
widget.param.watch(update_img, 'value')
widget.param.trigger('value')
pn.Column(widget, image)
```

In this example Param will await the asynchronous function and the image will be updated when the request completes.
In this example Param will await the asynchronous function and the image will be updated when the request completes.
4 changes: 2 additions & 2 deletions doc/how_to/concurrency/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ When deploying a Panel application to be accessed by multiple users they will of

1. `Load balancing`: A load balancer distributes network traffic between multiple instances of the Panel application. This ensures that the load is distributed across multiple servers but also requires a lot configuration and resources.
2. `Multi-process server instance`: Launches your app with multiple processes on a single machine. Much simpler to set up than a load balancer but the load is not distributed equally across processes and you are limited by the compute and memory resources on one machine.
2. `Threading`: Attempts to distribute processing across multiple threads. Effectiveness depends on the operations being performed, I/O bound and CPU bound operations that release the GIL can easily be made concurrent in this way.
2. `Threading`: Attempts to distribute processing across multiple threads. Effectiveness depends on the operations being performed, I/O bound and CPU bound operations that release the GIL can easily be made concurrent in this way.
3. `AsyncIO`: Allows asynchronously processing I/O bound operations. Effective for many concurrent I/O operations but requires rewriting your application and callbacks to make use of `async`/`await` paradigm.

## Scaling across processes
Expand Down Expand Up @@ -71,4 +71,4 @@ load_balancing
processes
threading
async
```
```
4 changes: 2 additions & 2 deletions doc/how_to/concurrency/manual_threading.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def callback():
text.value = "Queue empty"
c.release()
time.sleep(1)

thread = threading.Thread(target=callback)
thread.start()
```
Expand All @@ -41,4 +41,4 @@ button.on_click(on_click)
pn.Row(button, text).servable()
```

Since the processing happens on a separate thread the application itself can still remain responsive to further user input (such as putting new items on the queue).
Since the processing happens on a separate thread the application itself can still remain responsive to further user input (such as putting new items on the queue).
2 changes: 1 addition & 1 deletion doc/how_to/concurrency/processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Launching a Panel application on multiple processes is effectively a simpler way to scale your application. One major advantage is that it is easy to set up, when deploying your application with `panel serve` simply configure `--num-procs N`, where N is the number of processes. Generally choose an `N` that is no larger than the number of processors on your machine.

The main limitation is that the underlying Tornado multi-process mode does not balance connections across processes. Rather, any incoming connection will be assigned to the first server process that accepts it. Typically any idle process can get a new client regardless of how many clients it already has. In general the resulting distribution of clients across processes will be unequal. Moreover, this still uses significantly more resources since each process has the same overhead and all processes will be contending for the same memory and compute resources. However if your application is single-threaded and you have sufficient memory this is a simple way to make your application scale.
The main limitation is that the underlying Tornado multi-process mode does not balance connections across processes. Rather, any incoming connection will be assigned to the first server process that accepts it. Typically any idle process can get a new client regardless of how many clients it already has. In general the resulting distribution of clients across processes will be unequal. Moreover, this still uses significantly more resources since each process has the same overhead and all processes will be contending for the same memory and compute resources. However if your application is single-threaded and you have sufficient memory this is a simple way to make your application scale.
4 changes: 2 additions & 2 deletions doc/how_to/concurrency/threading.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Enable Automatic Threading

Using threading in Panel can either be enabled manually, e.g. by managing your own thread pool and dispatching concurrent tasks to it, or it can be managed by Panel itself by setting the `config.nthreads` parameter (or equivalently by setting it with `pn.extension(nthreads=...)`. This will start a `ThreadPoolExecutor` with the specified number of threads (or if set to `0` it will set the number of threads based on your system, i.e. `min(32, os.cpu_count() + 4)`).
Using threading in Panel can either be enabled manually, e.g. by managing your own thread pool and dispatching concurrent tasks to it, or it can be managed by Panel itself by setting the `config.nthreads` parameter (or equivalently by setting it with `pn.extension(nthreads=...)`. This will start a `ThreadPoolExecutor` with the specified number of threads (or if set to `0` it will set the number of threads based on your system, i.e. `min(32, os.cpu_count() + 4)`).

Whenever an event is generated or a periodic callback fires Panel will then automatically dispatch the event to the executor. An event in this case refers to any action generated on the frontend such as the manipulation of a widget by a user or the interaction with a plot. If you are launching an application with `panel serve` you should enable this option configure this option on the CLI by setting `--num-threads`.

Expand All @@ -15,7 +15,7 @@ def button_click(event):
print('Button clicked for the {event.new}th time.')
time.sleep(2) # Simulate long running operation
print('Finished processing {event.new}th click.')

button = pn.widgets.Button(name='Click me!')

button.on_click(button_click)
Expand Down
2 changes: 1 addition & 1 deletion doc/how_to/display/editor.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Develop Apps in an Editor

WIP
WIP
2 changes: 1 addition & 1 deletion doc/how_to/display/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ How to use the Preview functionality in JupyterLab to rapidly develop applicatio
notebook
editor
jupyterlab
```
```
2 changes: 1 addition & 1 deletion doc/how_to/display/jupyterlab.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Develop Apps in JupyterLab

WIP
WIP
8 changes: 4 additions & 4 deletions doc/how_to/display/notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pn.extension('vega', 'tabulator')

## Display output

One of the major benefits of notebook environments is that they support rich output. This means that if you place an object with rich output at the end of a cell the notebook will figure out how to render the rich representation. Panel uses this mechanism to ensure that all components return a rich representation:
One of the major benefits of notebook environments is that they support rich output. This means that if you place an object with rich output at the end of a cell the notebook will figure out how to render the rich representation. Panel uses this mechanism to ensure that all components return a rich representation:

```{pyodide}
pane = pn.panel('<marquee>Here is some custom HTML</marquee>')
Expand All @@ -41,7 +41,7 @@ To avoid having to put a Panel on the last line of a notebook cell, e.g. to disp
```{pyodide}
def display_marquee(text):
display(pn.panel('<marquee>{text}</marquee>'.format(text=text)))
display_marquee('This Panel was displayed from within a function')
```

Expand Down Expand Up @@ -70,7 +70,7 @@ Accordion(children=[pn.ipywidget(pane)])
```

To use Panel's ipywidgets support in JupyterLab, the following extensions have to be installed:

```
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install @bokeh/jupyter_bokeh
Expand All @@ -86,4 +86,4 @@ or using conda:

```
conda install -c bokeh jupyter_bokeh
```
```
6 changes: 3 additions & 3 deletions doc/how_to/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ How to access state related to the user session, HTTP request and URL arguments.
How to cache data across sessions and memoize the output of functions.
:::

:::{grid-item-card} {octicon}`versions;2.5em;sd-mr-1` Improve Performance
:::{grid-item-card} {octicon}`hourglass;2.5em;sd-mr-1` Improve Performance
:link: concurrency/index
:link-type: doc

Discover some tips and tricks instructing you on how you can improve the performance of your application.
:::

:::{grid-item-card} {octicon}`versions;2.5em;sd-mr-1` Improve Scalability
:::{grid-item-card} {octicon}`duplicate;2.5em;sd-mr-1` Improve Scalability
:link: concurrency/index
:link-type: doc

Discover various approaches telling you how to improve the scalability of your Panel application.
:::

:::{grid-item-card} {octicon}`versions;2.5em;sd-mr-1` Enable Profiling & Debugging
:::{grid-item-card} {octicon}`meter;2.5em;sd-mr-1` Enable Profiling & Debugging
:link: profiling/index
:link-type: doc

Expand Down
2 changes: 2 additions & 0 deletions doc/how_to/links/jscallbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Sometimes defining a simple link between to objects is not sufficient, e.g. when
To implement this we define a `jscallback`, which is triggered when the `Button.clicks` property changes and provide a number of `args` allowing us to access the values of the various widgets:

```{pyodide}
import panel as pn
value1 = pn.widgets.Spinner(value=0, width=75)
operator = pn.widgets.Select(value='*', options=['*', '+'], width=50, align='center')
value2 = pn.widgets.Spinner(value=0, width=75)
Expand Down
1 change: 1 addition & 0 deletions doc/how_to/param/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ As a straightforward example without any additional dependencies we will write a

```{pyodide}
import panel as pn
import param
import numpy as np
class Sine(param.Parameterized):
Expand Down
3 changes: 3 additions & 0 deletions doc/how_to/param/subobjects.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
``Parameterized`` objects often have parameter values which are themselves ``Parameterized`` objects, forming a tree-like structure. Panel allows you to edit not just the main object's parameters but also lets you drill down to the subobject. Let us first define some classes declaring a hierarchy of Shape classes which draw a Bokeh plot of the selected shape:

```{pyodide}
import panel
import param
from bokeh.plotting import figure
class Shape(param.Parameterized):
Expand Down
2 changes: 1 addition & 1 deletion doc/how_to/performance/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Discover how to enable throttling to reduce the number of events being processed
layout
throttling
```
```
2 changes: 1 addition & 1 deletion doc/how_to/performance/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ template.main.append(b)
template.main.append(c)
```

Doing this will ensure that the Bokeh.js layout engine considers each component separately and will speed up rendering a lot if `a`, `b` and `c` are deeply nested components.
Doing this will ensure that the Bokeh.js layout engine considers each component separately and will speed up rendering a lot if `a`, `b` and `c` are deeply nested components.
2 changes: 1 addition & 1 deletion doc/how_to/performance/throttling.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def output(value):
pn.bind(output, slider.param.value_throttled)
```

Alternatively you can also ensure that all sliders only update on mouse release if you set `pn.config.throttled = True`.
Alternatively you can also ensure that all sliders only update on mouse release if you set `pn.config.throttled = True`.
2 changes: 1 addition & 1 deletion doc/how_to/profiling/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ The `/admin` panel provides an overview of the current application and provides

When you have successfully enabled it you should be able to visit the `/admin` endpoint of your application, e.g. if you are serving locally on port 5006, visit `http://localhost:5006/admin`. You should now be greeted with the overview page, which provides some details about currently active sessions, running versions and resource usage (if `psutil` is installed):

<img src="../../_static/admin_overview.png" width="70%"></img>
<img src="../../_static/admin_overview.png" width="70%"></img>
10 changes: 5 additions & 5 deletions doc/how_to/profiling/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

When trying to understand the performance profiles or track down issues with an application the server logs are rarely sufficient to gain insights. For that reason Panel ships with an admin dashboard that allows tracking resource usage, user behavior, and provides ways of visualizing profiling output to discover bottlenecks in an application.

::::{grid} 1 2 2 2
::::{grid} 1 2 2 3
:gutter: 1 1 1 2

:::{grid-item-card} {octicon}`workflow;2.5em;sd-mr-1` Enable the Admin Panel
:link: load_balancing
:link: admin
:link-type: doc

Discover how-to enable the admin Panel to begin monitoring resource usage and user behavior.
:::

:::{grid-item-card} {octicon}`workflow;2.5em;sd-mr-1` Profile your Application
:link: processes
:link: profile
:link-type: doc

Discover how to enable profilers like snakeviz or memray to track down bottlenecks in your application.
:::

:::{grid-item-card} {octicon}`workflow;2.5em;sd-mr-1` View Application Logs
:link: processes
:link: logs
:link-type: doc

Discover how to view application logs in the admin dashboard.
Expand All @@ -36,4 +36,4 @@ Discover how to view application logs in the admin dashboard.
admin
profile
logs
```
```
2 changes: 1 addition & 1 deletion doc/how_to/profiling/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def get_clusters(x, y, n_clusters):
return ...
```

<img src="../../_static/admin_logs.png" width="80%"></img>
<img src="../../_static/admin_logs.png" width="80%"></img>
4 changes: 2 additions & 2 deletions doc/how_to/profiling/profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ In addition to profiling the launch step of an application it is often also impo
def get_clustering(event):
# some expensive calculation
...

widget.param.watch(my_callback, 'value')
```

Expand All @@ -49,4 +49,4 @@ Then we can request the named profile 'formatting' using the `pn.state.get_profi

```python
pn.state.get_profile('formatting')
```
```
2 changes: 2 additions & 0 deletions doc/how_to/state/busy.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Below we will create a little application to demonstrate this, we will create a
```{pyodide}
import time
import panel as pn
def processing(event):
# Some longer running task
time.sleep(1)
Expand Down

0 comments on commit 1e961b8

Please sign in to comment.