Skip to content

Commit 0c275a5

Browse files
authored
Merge branch 'main' into master
2 parents dec148b + f2ea922 commit 0c275a5

File tree

10 files changed

+61
-27
lines changed

10 files changed

+61
-27
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: Checkout
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1818

1919
- name: Base Setup
2020
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

.github/workflows/check-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
check_release:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
1919
- name: Check Release
2020
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717

1818
- name: Base Setup
1919
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16-
python-version: ["3.8", "3.11"]
16+
python-version: ["3.9", "3.13"]
1717

1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121

2222
- name: Base Setup
2323
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
@@ -37,6 +37,6 @@ jobs:
3737
check_links:
3838
runs-on: ubuntu-latest
3939
steps:
40-
- uses: actions/checkout@v3
40+
- uses: actions/checkout@v4
4141
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
4242
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1

jupyter_resource_usage/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def get(self):
9595
def _get_cpu_percent(self, all_processes):
9696
def get_cpu_percent(p):
9797
try:
98-
return p.cpu_percent(interval=0.05)
98+
return p.cpu_percent()
9999
# Avoid littering logs with stack traces complaining
100100
# about dead processes having no CPU usage
101101
except:

jupyter_resource_usage/tests/test_basic.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ def test_import_serverextension(self):
3030
nbapp_mock.web_app.settings = {"base_url": ""}
3131

3232
# mock these out for unit test
33-
with patch("tornado.ioloop.PeriodicCallback") as periodic_callback_mock, patch(
34-
"jupyter_resource_usage.server_extension.ResourceUseDisplay"
35-
) as resource_use_display_mock, patch(
36-
"jupyter_resource_usage.server_extension.PrometheusHandler"
37-
) as prometheus_handler_mock, patch(
38-
"jupyter_resource_usage.server_extension.PSUtilMetricsLoader"
39-
) as psutil_metrics_loader:
33+
with (
34+
patch("tornado.ioloop.PeriodicCallback") as periodic_callback_mock,
35+
patch(
36+
"jupyter_resource_usage.server_extension.ResourceUseDisplay"
37+
) as resource_use_display_mock,
38+
patch(
39+
"jupyter_resource_usage.server_extension.PrometheusHandler"
40+
) as prometheus_handler_mock,
41+
patch(
42+
"jupyter_resource_usage.server_extension.PSUtilMetricsLoader"
43+
) as psutil_metrics_loader,
44+
):
4045
# load up with mock
4146
load_jupyter_server_extension(nbapp_mock)
4247

packages/labextension/src/index.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ILabShell,
33
JupyterFrontEnd,
44
JupyterFrontEndPlugin,
5+
JupyterLab,
56
} from '@jupyterlab/application';
67

78
import { IToolbarWidgetRegistry } from '@jupyterlab/apputils';
@@ -70,14 +71,25 @@ const resourceStatusPlugin: JupyterFrontEndPlugin<void> = {
7071
id: '@jupyter-server/resource-usage:status-item',
7172
autoStart: true,
7273
requires: [ITranslator],
73-
optional: [IStatusBar],
74+
optional: [IStatusBar, JupyterLab.IInfo],
7475
activate: (
7576
app: JupyterFrontEnd,
7677
translator: ITranslator,
77-
statusBar: IStatusBar | null
78+
statusBar: IStatusBar | null,
79+
info: JupyterLab.IInfo | null
7880
) => {
81+
const refreshRate = DEFAULT_REFRESH_RATE;
82+
7983
const trans = translator.load('jupyter-resource-usage');
80-
const item = new ResourceUsageStatus(trans);
84+
const item = new ResourceUsageStatus(trans, {
85+
refreshRate,
86+
refreshStandby: () => {
87+
if (info) {
88+
return !info.isConnected || 'when-hidden';
89+
}
90+
return 'when-hidden';
91+
},
92+
});
8193

8294
if (statusBar) {
8395
statusBar.registerStatusItem(resourceStatusPlugin.id, {
@@ -98,11 +110,12 @@ const systemMonitorPlugin: JupyterFrontEndPlugin<void> = {
98110
id: '@jupyter-server/resource-usage:topbar-item',
99111
autoStart: true,
100112
requires: [IToolbarWidgetRegistry],
101-
optional: [ISettingRegistry],
113+
optional: [ISettingRegistry, JupyterLab.IInfo],
102114
activate: async (
103115
app: JupyterFrontEnd,
104116
toolbarRegistry: IToolbarWidgetRegistry,
105-
settingRegistry: ISettingRegistry | null
117+
settingRegistry: ISettingRegistry | null,
118+
info: JupyterLab.IInfo | null
106119
) => {
107120
let enablePlugin = DEFAULT_ENABLE_SYSTEM_MONITOR;
108121
let refreshRate = DEFAULT_REFRESH_RATE;
@@ -126,7 +139,15 @@ const systemMonitorPlugin: JupyterFrontEndPlugin<void> = {
126139
diskLabel = diskSettings.label;
127140
}
128141

129-
const model = new ResourceUsage.Model({ refreshRate });
142+
const model = new ResourceUsage.Model({
143+
refreshRate,
144+
refreshStandby: () => {
145+
if (info) {
146+
return !info.isConnected || 'when-hidden';
147+
}
148+
return 'when-hidden';
149+
},
150+
});
130151
await model.refresh();
131152

132153
if (enablePlugin && model.cpuAvailable) {

packages/labextension/src/model.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ export namespace ResourceUsage {
6464
frequency: {
6565
interval: options.refreshRate,
6666
backoff: true,
67+
max: 300 * 1000,
6768
},
6869
name: '@jupyterlab/statusbar:ResourceUsage#metrics',
70+
standby: options.refreshStandby || 'when-hidden',
6971
});
7072
this._poll.ticked.connect((poll) => {
7173
const { payload, phase } = poll.state;
@@ -326,6 +328,11 @@ export namespace ResourceUsage {
326328
* The refresh rate (in ms) for querying the server.
327329
*/
328330
refreshRate: number;
331+
332+
/**
333+
* When the model stops polling the API. Defaults to `when-hidden`.
334+
*/
335+
refreshStandby?: Poll.Standby | (() => boolean | Poll.Standby);
329336
}
330337

331338
/**

packages/labextension/src/resourceUsage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export class ResourceUsageStatus extends VDomRenderer<ResourceUsage.Model> {
2020
/**
2121
* Construct a new resource usage status item.
2222
*/
23-
constructor(trans: TranslationBundle) {
24-
super(new ResourceUsage.Model({ refreshRate: 5000 }));
23+
constructor(trans: TranslationBundle, options: ResourceUsage.Model.IOptions) {
24+
super(new ResourceUsage.Model(options));
2525
this._trans = trans;
2626
}
2727

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-backend = "hatchling.build"
1010
name = "jupyter-resource-usage"
1111
description = "Jupyter Extension to show resource usage"
1212
readme = "README.md"
13-
requires-python = ">=3.8"
13+
requires-python = ">=3.9"
1414
authors = [
1515
{ name = "Jupyter Development Team" },
1616
]
@@ -30,15 +30,16 @@ classifiers = [
3030
"License :: OSI Approved :: BSD License",
3131
"Programming Language :: Python",
3232
"Programming Language :: Python :: 3",
33-
"Programming Language :: Python :: 3.8",
3433
"Programming Language :: Python :: 3.9",
3534
"Programming Language :: Python :: 3.10",
3635
"Programming Language :: Python :: 3.11",
36+
"Programming Language :: Python :: 3.12",
37+
"Programming Language :: Python :: 3.13",
3738
]
3839
dependencies = [
3940
"jupyter_server>=2.0",
4041
"prometheus_client",
41-
"psutil~=5.6",
42+
"psutil>=5.6",
4243
"pyzmq>=19",
4344
]
4445
dynamic = ["version"]
@@ -126,7 +127,7 @@ default = ""
126127

127128
[tool.jupyter-releaser.hooks]
128129
before-build-npm = [
129-
"python -m pip install jupyterlab~=4.0",
130+
"python -m pip install 'jupyterlab>=4.0,<5'",
130131
"jlpm",
131132
"jlpm clean",
132133
"jlpm build:prod",

0 commit comments

Comments
 (0)