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

NotImplementedError: can't find current frequency file #60

Closed
Lucas-C opened this issue Sep 29, 2022 · 4 comments · Fixed by #61
Closed

NotImplementedError: can't find current frequency file #60

Lucas-C opened this issue Sep 29, 2022 · 4 comments · Fixed by #61

Comments

@Lucas-C
Copy link

Lucas-C commented Sep 29, 2022

Describe the bug
After installing pytest-monitor to plug it inside https://github.com/PyFPDF/fpdf2 a stacktrace was raised when calling pytest

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/PyFPDF/fpdf2
  2. Run pip install --upgrade . pytest-monitor -r test/requirements.txt in the cloned repo directory
  3. Run pytest

Expected behavior
No error

Stacktrace

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/_pytest/main.py", line 266, in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pluggy/_callers.py", line 34, in _multicall
INTERNALERROR>     next(gen)  # first yield
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pytest_monitor/pytest_monitor.py", line 194, in pytest_sessionstart
INTERNALERROR>     session.pytest_monitor.compute_info(session.config.option.mtr_description,
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pytest_monitor/session.py", line 85, in compute_info
INTERNALERROR>     self.set_environment_info(ExecutionContext())
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/pytest_monitor/sys_utils.py", line 72, in __init__
INTERNALERROR>     self.__cpu_freq_base = psutil.cpu_freq().current
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/psutil/__init__.py", line 1857, in cpu_freq
INTERNALERROR>     ret = _psplatform.cpu_freq()
INTERNALERROR>   File "/home/user/.local/share/virtualenvs/fpdf2/lib/python3.8/site-packages/psutil/_pslinux.py", line 701, in cpu_freq
INTERNALERROR>     raise NotImplementedError(
INTERNALERROR> NotImplementedError: can't find current frequency file

Desktop (please complete the following information):

  • OS: Linux (Ubuntu 20.04.4 LTS through WSL)
  • Python version: 3.8
  • Pytest version: 7.1.2
  • pytest-monitor version: 1.6.4
@js-dieu
Copy link
Collaborator

js-dieu commented Oct 10, 2022

Hi @Lucas-C

Apologies for the delay and thanks for reporting!
It seems psutil is confused with your system. I think it will look for /proc/cpuinfo but such files do not seems to exists.

I suggest to report that point to psutil directly.

@Lucas-C
Copy link
Author

Lucas-C commented Oct 10, 2022

This is indeed an issue with psutil & WSL: giampaolo/psutil#1251

While support for this is added, could you consider having a fallback?
Like other libs did: google/deepvariant#191 (comment)

@js-dieu
Copy link
Collaborator

js-dieu commented Oct 10, 2022

You are absolutely right. I think that 2 issues is enough for implementing it especially with the psutil team having difficulties in solving these issues.
I'll do my best to do it quickly.
I am thinking about a two times fallback similar to:

try:
   freq = psutil.cpu_freq()
   return freq.current if freq is not None else 0.0
except NotImplementedError:
    return float(os.environ.get('PYTEST_MONITOR_CPU_FREQ', '0')

I think that would put your exception away and match your use case.

@Lucas-C
Copy link
Author

Lucas-C commented Oct 10, 2022

That look great!
Thank you for taking a look at this @js-dieu 😊

js-dieu added a commit to js-dieu/pytest-monitor that referenced this issue Oct 16, 2022
Allow to set the CPU frequency from an environment variable.
Additionally, whenever psutil cannot resolve the cpu frequency, we use the same
fallback mechanism.
Added environment variables:
 - PYTEST_MONITOR_FORCE_CPU_FREQ (to overcome psutil)
 - PYTEST_MONITOR_CPU_FREQ (to set a CPU frequency value)
js-dieu added a commit to js-dieu/pytest-monitor that referenced this issue Oct 16, 2022
@js-dieu js-dieu mentioned this issue Oct 16, 2022
14 tasks
js-dieu added a commit to js-dieu/pytest-monitor that referenced this issue Oct 22, 2022
Allow to set the CPU frequency from an environment variable.
Additionally, whenever psutil cannot resolve the cpu frequency, we use the same
fallback mechanism.
Added environment variables:
 - PYTEST_MONITOR_FORCE_CPU_FREQ (to overcome psutil)
 - PYTEST_MONITOR_CPU_FREQ (to set a CPU frequency value)
js-dieu added a commit to js-dieu/pytest-monitor that referenced this issue Oct 22, 2022
js-dieu added a commit that referenced this issue Oct 22, 2022
Allow to set the CPU frequency from an environment variable.
Additionally, whenever psutil cannot resolve the cpu frequency, we use the same
fallback mechanism.
Added environment variables:
 - PYTEST_MONITOR_FORCE_CPU_FREQ (to overcome psutil)
 - PYTEST_MONITOR_CPU_FREQ (to set a CPU frequency value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants