Skip to content

Commit

Permalink
avoid circular import if nbclassic has shimmed jupyter_server in for …
Browse files Browse the repository at this point in the history
…notebook

which happens when `notebook` is entirely not present,
and results in the same module being imported twice,
ensuring all metrics are always defined twice
  • Loading branch information
minrk committed Mar 22, 2023
1 parent 429b233 commit c75004d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions jupyter_server/prometheus/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
from prometheus_client import Counter

try:
import notebook

if notebook.__name__ != "notebook":
# avoid double-importing myself if nbclassic is shimming jupyter_server into notebook,
# in which case notebook.__name__ will be 'jupyter_server'
_msg = "Not importing jupyter_server metrics under two names"
raise ImportError(_msg)
# Jupyter Notebook also defines these metrics. Re-defining them results in a ValueError.
# Try to de-duplicate by using the ones in Notebook if available.
# See https://github.com/jupyter/jupyter_server/issues/209
Expand Down

0 comments on commit c75004d

Please sign in to comment.