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

Cannot catch KernelModuleLoadError #110

Open
ggstuart opened this issue Jul 3, 2021 · 1 comment
Open

Cannot catch KernelModuleLoadError #110

ggstuart opened this issue Jul 3, 2021 · 1 comment
Labels

Comments

@ggstuart
Copy link

ggstuart commented Jul 3, 2021

Hi, I was trying to catch the KernelModuleLoadError and handle it.

from w1thermsensor.errors import KernelModuleLoadError

However, its not possible to import the exception without raising the error.

This seems to be because your __init__.py module calls the load_kernel_modules() method immediately.

So its not possible to get a reference to the error without raising it first.

Any ideas about how I could work around this? Or ways to rearrange things?

@timofurrer
Copy link
Owner

indeed 🤦

Any ideas about how I could work around this? Or ways to rearrange things?

I don't think it'll be possible unless I move the auto-loading of the kernel module to w1thermsensor.core and don't import that in __init__.py - and with that basically making the user to import w1thermsensor manually.
AFAIK there is no way to import something like w1thermsensor.error as module without the w1thermsensor/__init__.py being imported, too ...

As a work around you could disable the auto-loading and just call it yourself:

# set W1THERMSENSOR_NO_KERNEL_MODULE=1 in environment (either before launching your app or in the app)
from w1thermsensor import W1ThermSensor, load_kernel_modules, KernelModuleLoadError

try:
   load_kernel_modules()
except KernelModuleLoadError as exc:
   ...

Or you are basically fine with just catching it as Exception ... but I agree to your point that with that the KernelModuleLoadError is basically useless.

I'm open for suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants