jupyter-resource-usage icon indicating copy to clipboard operation
jupyter-resource-usage copied to clipboard

Getting "AttributeError: can't set attribute" error when starting Jupyter Lab with mem_limit and/or cpu_limit

Open mleida-stratio opened this issue 4 years ago • 2 comments

Hi all, I am trying to expose metric via Prometheus. Versions I am using are: python 3.6 jupyterlab 1.2.15 notebook 6.0.3 [email protected] [email protected]

i am passing MEM_LIMIT and CPU_LIMIT as environment variables from the jupyter hub spawner. I am getting the following error when starting JupyterLab with nbresuse 0.3.4

[E 2020-05-21 09:18:05.132 admin ioloop:801] Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x7ffa31de98c8>, <Future finished exception=AttributeError("can't set attribute",)>) Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/tornado/ioloop.py", line 758, in _run_callback ret = callback() File "/usr/local/lib/python3.6/dist-packages/tornado/stack_context.py", line 300, in null_wrapper return fn(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/tornado/ioloop.py", line 779, in _discard_future_result future.result() File "/usr/local/lib/python3.6/dist-packages/tornado/gen.py", line 307, in wrapper result = func(*args, **kwargs) File "/usr/lib/python3.6/types.py", line 248, in wrapped coro = func(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/nbresuse/prometheus.py", line 34, in __call__ metrics = self.apply_memory_limits(memory_metrics()) File "/usr/local/lib/python3.6/dist-packages/nbresuse/prometheus.py", line 49, in apply_memory_limits metrics.max_memory = self.config.mem_limit AttributeError: can't set attribute

the exception is trhown here and from my knowledge it is because in that line it is trying to set a parameter in a NamedTuple which is immutable. I managet to solve it by using _replace method instead. I wander if i am doign something wrong or this is a bug in the last release. I the second case, i can create a pull request with the fix.

Ciao.

mleida-stratio avatar May 21 '20 09:05 mleida-stratio

@mleida-stratio would it be possible to use JupyterLab 2.x and nbresuse==0.3.3?

0.3.4 is not compatible with JupyterLab (#36). Also the other lab extensions mentioned above have been updated to work with JupyterLab 2.x.

jtpio avatar May 22 '20 07:05 jtpio

Hi, thanks for the quick reply. I understand that the topbar and system monitor extensions will not work. However i am only interested in exposing the Prometheus metrics endpoind. I managed to get it working but i had to modify the code the way i commented in the first message. My questio is if this is a bug in nbresuse 0.3.4 (is trying to modify an nonmutable object) or if i am missing something.

cheers

mleida-stratio avatar May 22 '20 07:05 mleida-stratio