Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force new instance of ASyncHTTPclient #10

Merged
merged 2 commits into from
Apr 10, 2024
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
6 changes: 5 additions & 1 deletion jupyter_power_usage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from jupyter_server.utils import url_path_join as ujoin

from ._version import __version__
from ._version import __version__ # noqa
from .api import ElectrictyMapsHandler
from .api import PowerMetricHandler
from .config import PowerUsageDisplay
from .metrics import CpuPowerUsage
from .metrics import GpuPowerUsage


def _jupyter_server_extension_points():
return [{"module": "jupyter_power_usage"}]


def _jupyter_labextension_paths():
return [{"src": "labextension", "dest": "@mahendrapaipuri/jupyter-power-usage"}]

Expand Down
11 changes: 9 additions & 2 deletions jupyter_power_usage/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ class ElectrictyMapsHandler(JupyterHandler):
The purpose of this proxy is to provide authentication to the API requests.
"""

client = AsyncHTTPClient()
# Force a new instance to not to mess up with other instances that might exist in
# JupyterHub or other Jupyter related stacks
#
# Without this we noticed that JupyterHub will fail to spawn instances when internal
# TLS is on. The reason is that this new instantiation will override the already
# existing instance in single user extension that has SSL context configured. So
# we lose SSL context and hence cert verification will fail eventually failing spawn.
client = AsyncHTTPClient(force_instance=True)

def initialize(self):
# Get access token(s) from config
Expand All @@ -119,7 +126,7 @@ def initialize(self):

@web.authenticated
async def get(self, path):
"""Return emission factor data from electticity maps"""
"""Return emission factor data from electricity maps"""
try:
query = self.request.query_arguments
params = {key: query[key][0].decode() for key in query}
Expand Down
Loading