Skip to content

Commit 4970166

Browse files
committed
Limit the backend timeout to 1+2+3=6 seconds total
1 parent f9e0a04 commit 4970166

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

jupyterlab_kernel_usage/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import json
32
from pathlib import Path
43

jupyterlab_kernel_usage/handlers.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import asyncio
21
import ipykernel
32
import json
43
import tornado
54
import zmq
65

7-
from functools import partial
8-
96
from jupyter_server.base.handlers import APIHandler
10-
from jupyter_server.utils import url_path_join, ensure_async
7+
from jupyter_server.utils import url_path_join
118
from jupyter_client.jsonutil import date_default
129

1310
from packaging import version
1411

1512

1613
USAGE_IS_SUPPORTED = version.parse("6.9.0") <= version.parse(ipykernel.__version__)
1714

15+
MAX_RETRIES = 3
16+
1817

1918
class RouteHandler(APIHandler):
2019

@@ -38,9 +37,8 @@ async def get(self, matched_part=None, *args, **kwargs):
3837
poller = zmq.Poller()
3938
control_socket = control_channel.socket
4039
poller.register(control_socket, zmq.POLLIN)
41-
while True:
42-
timeout = 100
43-
timeout_ms = int(1000 * timeout)
40+
for i in range(1, MAX_RETRIES + 1):
41+
timeout_ms = 1000 * i
4442
events = dict(poller.poll(timeout_ms))
4543
if not events:
4644
self.write(json.dumps({}))

0 commit comments

Comments
 (0)