Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

Commit

Permalink
Limit the backend timeout to 1+2+3=6 seconds total
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Dec 12, 2022
1 parent f9e0a04 commit 4970166
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion jupyterlab_kernel_usage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import json
from pathlib import Path

Expand Down
12 changes: 5 additions & 7 deletions jupyterlab_kernel_usage/handlers.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import asyncio
import ipykernel
import json
import tornado
import zmq

from functools import partial

from jupyter_server.base.handlers import APIHandler
from jupyter_server.utils import url_path_join, ensure_async
from jupyter_server.utils import url_path_join
from jupyter_client.jsonutil import date_default

from packaging import version


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

MAX_RETRIES = 3


class RouteHandler(APIHandler):

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

0 comments on commit 4970166

Please sign in to comment.