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

Unable to load driver: [Errno 16] Resource busy #3

Open
tfilo opened this issue Feb 23, 2022 · 10 comments
Open

Unable to load driver: [Errno 16] Resource busy #3

tfilo opened this issue Feb 23, 2022 · 10 comments

Comments

@tfilo
Copy link

tfilo commented Feb 23, 2022

Hello, after a more than year I upgraded raspbian to newest version. Now I am not able to run weewx on python 2 anymore (which was solving this problem for me). With python 3 i still see this king of error. It occur every few days/weeks. After this error occur in logs, weewx will stop record data. I know that this is not supported hardware anymore but i still hope someone can help to fix it. It worked with python 2 for more than 8 years without problem. I use version 4.6.2 of weewx and latest wmr200py.

Feb 22 21:16:32 meteo weewx[18340] ERROR user.wmr200: read_device() USB Error Reason:[Errno 110] Operation timed out
Feb 22 21:16:32 meteo weewx[18340] ERROR user.wmr200: USB device read error
Feb 22 21:16:33 meteo weewx[18340] ERROR user.wmr200: USB polling thread unexpectedly terminated
Feb 22 21:16:33 meteo weewx[18340] INFO weewx.engine: Main loop exiting. Shutting engine down.
Feb 22 21:16:33 meteo weewx[18340] INFO weewx.engine: Shutting down StdReport thread
Feb 22 21:16:33 meteo weewx[18340] INFO user.wmr200: USB polling thread expired
Feb 22 21:16:33 meteo weewx[18340] CRITICAL __main__: Caught WeeWxIOError: USB polling thread unexpectedly terminated
Feb 22 21:16:33 meteo weewx[18340] CRITICAL __main__:     ****  Waiting 60 seconds then retrying...
Feb 22 21:17:01 meteo CRON[32530]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 22 21:17:33 meteo weewx[18340] INFO __main__: retrying...
Feb 22 21:17:33 meteo weewx[18340] INFO weewx.engine: Loading station type WMR200 (user.wmr200)
Feb 22 21:17:33 meteo weewx[18340] INFO user.wmr200: driver version is 3.5.2
Feb 22 21:17:33 meteo weewx[18340] INFO user.wmr200: sensor map is {'altimeter': 'altimeter', 'pressure': 'pressure', 'windSpeed': 'wind_speed', 'windDir': 'wind_dir', 'windGus
t': 'wind_gust', 'windBatteryStatus': 'battery_status_wind', 'inTemp': 'temperature_0', 'outTemp': 'temperature_1', 'extraTemp1': 'temperature_2', 'extraTemp2': 'temperature_3', 'extraTemp3': 'temperature_4', 'extraTemp4': 'temperature_5', 'extraTemp5': 'temperature_6', 'extraTemp6': 'temperature_7', 'extraTemp7': 'temperature_8', 'inHumidity': 'humidity_0', 'outHumidity': 'humidity_1', 'extraHumid1': 'humidity_2', 'extraHumid2': 'humidity_3', 'extraHumid3': 'humidity_4', 'extraHumid4': 'humidity_5', 'extraHumid5': 'humidity_6', 'extraHumid6': 'humidity_7', 'extraHumid7': 'humidity_8', 'inHeatindex': 'heatindex_0', 'heatindex': 'heatindex_1', 'heatindex1': 'heatindex_2', 'heatindex2': 'heatindex_3', 'heatindex3': 'heatindex_4', 'heatindex4': 'heatindex_5', 'heatindex5': 'heatindex_6', 'heatindex6': 'heatindex_7', 'heatindex7': 'heatindex_8', 'outTempBatteryStatus': 'battery_status_out', 'rain': 'rain', 'rainTotal': 'rain_total', 'rainRate': 'rain_rate', 'hourRain': 'rain_hour', 'rain24': 'rain_24', 'rainBatteryStatus': 'battery_status_rain', 'UV': 'uv', 'uvBatteryStatus': 'battery_status_uv', 'windchill': 'windchill', 'forecastIcon': 'forecast_icon', 'outTempFault': 'out_fault', 'windFault': 'wind_fault', 'uvFault': 'uv_fault', 'rainFault': 'rain_fault', 'clockUnsynchronized': 'clock_unsynchronized'}
Feb 22 21:17:33 meteo weewx[18340] CRITICAL user.wmr200: open_device() Unable to claim USB interface. Reason: [Errno 16] Resource busy
Feb 22 21:17:33 meteo weewx[18340] ERROR weewx.engine: Import of driver failed: [Errno 16] Resource busy (<class 'weewx.WakeupError'>)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****  Traceback (most recent call last):
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 195, in open_device
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      self.handle.claimInterface(self.interface)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/legacy.py", line 230, in claimInterface
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      util.claim_interface(self.dev, interface)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/util.py", line 205, in claim_interface
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      device._ctx.managed_claim_interface(device, interface)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/core.py", line 102, in wrapper
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      return f(self, *args, **kwargs)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/core.py", line 167, in managed_claim_interface
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      self.backend.claim_interface(self.handle, i)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 811, in claim_interface
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 595, in _check
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      raise USBError(_strerror(ret), ret, _libusb_errno[ret])
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****  usb.core.USBError: [Errno 16] Resource busy
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****  
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****  During handling of the above exception, another exception occurred:
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****  
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****  Traceback (most recent call last):
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/weewx/engine.py", line 119, in setupStation
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      self.console = loader_function(config_dict, self)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 58, in loader
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      return WMR200(**config_dict[DRIVER_NAME])
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 1470, in __init__
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      self.usb_device.open_device(vendor_id, product_id)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 198, in open_device
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****      raise weewx.WakeupError(exception)
Feb 22 21:17:33 meteo weewx[18340] CRITICAL weewx.engine:     ****  weewx.WakeupError: [Errno 16] Resource busy
Feb 22 21:17:33 meteo weewx[18340] CRITICAL __main__: Unable to load driver: [Errno 16] Resource busy
Feb 22 21:17:33 meteo weewx[18340] CRITICAL __main__:     ****  Exiting...
@mr-bryn
Copy link

mr-bryn commented Feb 28, 2022

I'm seeing the same issue - Errno16 every couple of days.
Previously I had been running on a raspberry pi with python 2 version of weewx, and it was quite stable.
I've recently replaced the raspberry pi and moved to python 3 weewx v4.6.2 with the latest wmr200 driver available v3.5.2

My error stack seems to begin with something about a checksum error.

Feb 28 07:41:20 wyse weewx[201734] WARNING user.wmr200: Skipped bytes before resync:9
Feb 28 07:41:20 wyse weewx[201734] ERROR user.wmr200: Checksum miscompare act:0x0000 exp:0x02d3 packet:d3 02 
Feb 28 07:41:20 wyse weewx[201734] INFO weewx.engine: Main loop exiting. Shutting engine down.
Feb 28 07:41:20 wyse weewx[201734] INFO weewx.engine: Shutting down StdReport thread
Feb 28 07:41:22 wyse weewx[201734] INFO weewx.cheetahgenerator: Generated 8 files for report SeasonsReport in 1.80 seconds
Feb 28 07:41:23 wyse weewx[201734] INFO weewx.imagegenerator: Generated 11 images for report SeasonsReport in 1.03 seconds
Feb 28 07:41:23 wyse weewx[201734] INFO weewx.reportengine: Copied 0 files to /var/www/html/weewx
Feb 28 07:41:23 wyse weewx[201734] INFO weewx.cheetahgenerator: Generated 6 files for report SmartphoneReport in 0.07 seconds
Feb 28 07:41:23 wyse weewx[201734] INFO weewx.imagegenerator: Generated 6 images for report SmartphoneReport in 0.29 seconds
Feb 28 07:41:23 wyse weewx[201734] INFO weewx.reportengine: Copied 0 files to /var/www/html/weewx/smartphone
Feb 28 07:41:23 wyse weewx[201734] INFO user.wmr200: USB polling device thread exiting
Feb 28 07:41:23 wyse weewx[201734] INFO user.wmr200: USB polling thread expired
Feb 28 07:41:23 wyse weewx[201734] CRITICAL __main__: Caught WeeWxIOError: Checksum miscompare act:0x0000 exp:0x02d3
Feb 28 07:41:23 wyse weewx[201734] CRITICAL __main__:     ****  Waiting 60 seconds then retrying...
Feb 28 07:42:23 wyse weewx[201734] INFO __main__: retrying...
Feb 28 07:42:23 wyse weewx[201734] INFO weewx.engine: Loading station type WMR200 (user.wmr200)
Feb 28 07:42:23 wyse weewx[201734] INFO user.wmr200: driver version is 3.5.2
Feb 28 07:42:23 wyse weewx[201734] INFO user.wmr200: sensor map is {'altimeter': 'altimeter', 'pressure': 'pressure', 'windSpeed': 'wind_speed', 'windDir': 'wind_dir', 'windGust': 'wind_gust', 'windBatteryStatus': 'battery_status_wind', 'inTemp': 'temperature_0', 'outTemp': 'temperature_1', 'extraTemp1': 'temperature_2', 'extraTemp2': 'temperature_3', 'extraTemp3': 'temperature_4', 'extraTemp4': 'temperature_5', 'extraTemp5': 'temperature_6', 'extraTemp6': 'temperature_7', 'extraTemp7': 'temperature_8', 'inHumidity': 'humidity_0', 'outHumidity': 'humidity_1', 'extraHumid1': 'humidity_2', 'extraHumid2': 'humidity_3', 'extraHumid3': 'humidity_4', 'extraHumid4': 'humidity_5', 'extraHumid5': 'humidity_6', 'extraHumid6': 'humidity_7', 'extraHumid7': 'humidity_8', 'inHeatindex': 'heatindex_0', 'heatindex': 'heatindex_1', 'heatindex1': 'heatindex_2', 'heatindex2': 'heatindex_3', 'heatindex3': 'heatindex_4', 'heatindex4': 'heatindex_5', 'heatindex5': 'heatindex_6', 'heatindex6': 'heatindex_7', 'heatindex7': 'heatindex_8', 'outTempBatteryStatus': 'battery_status_out', 'rain': 'rain', 'rainTotal': 'rain_total', 'rainRate': 'rain_rate', 'hourRain': 'rain_hour', 'rain24': 'rain_24', 'rainBatteryStatus': 'battery_status_rain', 'UV': 'uv', 'uvBatteryStatus': 'battery_status_uv', 'windchill': 'windchill', 'forecastIcon': 'forecast_icon', 'outTempFault': 'out_fault', 'windFault': 'wind_fault', 'uvFault': 'uv_fault', 'rainFault': 'rain_fault', 'clockUnsynchronized': 'clock_unsynchronized'}
Feb 28 07:42:23 wyse weewx[201734] CRITICAL user.wmr200: open_device() Unable to claim USB interface. Reason: [Errno 16] Resource busy
Feb 28 07:42:23 wyse weewx[201734] ERROR weewx.engine: Import of driver failed: [Errno 16] Resource busy (<class 'weewx.WakeupError'>)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****  Traceback (most recent call last):
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 195, in open_device
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      self.handle.claimInterface(self.interface)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/legacy.py", line 230, in claimInterface
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      util.claim_interface(self.dev, interface)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/util.py", line 205, in claim_interface
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      device._ctx.managed_claim_interface(device, interface)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/core.py", line 102, in wrapper
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      return f(self, *args, **kwargs)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/core.py", line 167, in managed_claim_interface
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      self.backend.claim_interface(self.handle, i)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 811, in claim_interface
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 595, in _check
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      raise USBError(_strerror(ret), ret, _libusb_errno[ret])
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****  usb.core.USBError: [Errno 16] Resource busy
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****  
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****  During handling of the above exception, another exception occurred:
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****  
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****  Traceback (most recent call last):
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/weewx/engine.py", line 119, in setupStation
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      self.console = loader_function(config_dict, self)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 58, in loader
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      return WMR200(**config_dict[DRIVER_NAME])
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 1470, in __init__
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      self.usb_device.open_device(vendor_id, product_id)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****    File "/usr/share/weewx/user/wmr200.py", line 198, in open_device
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****      raise weewx.WakeupError(exception)
Feb 28 07:42:23 wyse weewx[201734] CRITICAL weewx.engine:     ****  weewx.WakeupError: [Errno 16] Resource busy
Feb 28 07:42:23 wyse weewx[201734] CRITICAL __main__: Unable to load driver: [Errno 16] Resource busy
Feb 28 07:42:23 wyse weewx[201734] CRITICAL __main__:     ****  Exiting...

@tfilo
Copy link
Author

tfilo commented Feb 28, 2022

I don’t know python so i am not able to fix it but i will try to implement some workaround. Watch logs automatically and when this error occuress it will call sudo systemctl restart weewx.service. I hope i will find time to do it during weekend. It will not fix this issue but it will at least automate restarts when this error occure.

@mr-bryn
Copy link

mr-bryn commented Feb 28, 2022

@tfilo I'd very much appreciate if you are able to share your workaround once it's setup.
Currently the only way I know to fix it is manually restart weewx. I was almost thinking to create a cron job to restart weewx every hour?

@tfilo
Copy link
Author

tfilo commented Mar 6, 2022

@mr-bryn It is not tested yet! Use on your own risk !!! It will work only if you have weewx managed by systemctl (if you installed using apt it should work). Idea is that you create file restartOnError.sh with following content. Set it to be owned by root (sudo chown roor:root restartOnError.sh), for security reason allow to read/write to file only to root (sudo chmod 700 restartOnError.sh). Than add this file to cron for root user. (sudo crontab -e) and add something like this:

CRON record

# RESTART WEEEWX ON ERROR
*/5 * *   *   *     /path/to/file/restartOnError.sh >/dev/null 2>&1

restartOnError.sh

#!/bin/bash

error16=$(systemctl status weewx.service | grep 'weewx\[[0-9]*\] CRITICAL __main__: Unable to load driver: \[Errno 16\] Resource busy')

if [ -z "$error16" ]
then
      echo "$(date +%Y-%m-%d_%H:%M:%S) ok" >> $HOME/restart_log.txt
else
      echo "$(date +%Y-%m-%d_%H:%M:%S) restarting weewx" >> $HOME/restart_log.txt
      $(systemctl restart weewx.service)
fi

This is not fix for this error, it is just ugly workaround to deal with this errors automatically until fix for this issue is found. It will log to root's home directory into file /root/restart_log.txt so there is easy to check if it restarted weewx or not. I will test it myself in next few weeks. For now (almost week I am without error so I must wait to see if it works like expected).

Modified error16 variable line!!! (11.3.2022)
Modified added regex instead of fixed pid number thanks to @mr-bryn (17.3.2022)

@tfilo
Copy link
Author

tfilo commented Mar 11, 2022

@mr-bryn This error just occured to me, so i tested my script and modified third line where error16 variable is assigned. Now it is able to find error in log correctly and restart weewx by itself.

@mr-bryn
Copy link

mr-bryn commented Mar 14, 2022

Thanks @tfilo , I haven't had time yet to set up your script, but luckily my station has continued operating anyway. I'll report back once it's in place.

@mr-bryn
Copy link

mr-bryn commented Mar 16, 2022

@tfilo I've made a few tweaks to the script because I'm not as familiar with systemctl, also I noticed the grep line was looking for a specific number (is this the pid maybe?), so it should match any series of digits there now.
Now I just have to wait for the error to occur again!

#!/bin/bash

error16=$(sudo /usr/sbin/service weewx status | grep 'weewx\[[0-9]*\] CRITICAL __main__: Unable to load driver: \[Errno 16\] Resource busy')

if [ -z "$error16" ]
then
      echo "$(date +%Y-%m-%d_%H:%M:%S) ok" >> $HOME/restart_log.txt
else
      echo "$(date +%Y-%m-%d_%H:%M:%S) restarting weewx" >> $HOME/restart_log.txt
      $(sudo /usr/sbin/service weewx restart)
fi

@tfilo
Copy link
Author

tfilo commented Mar 16, 2022

@mr-bryn thanks for feedback, yes it is probably pid number, i will fix this part in my script too.

@mr-bryn
Copy link

mr-bryn commented May 5, 2022

@tfilo Since I've put the script in place it's successfully restarted weewx a dozen or so times and I haven't had to intervene at all. Thanks for helping solve this!

@tfilo
Copy link
Author

tfilo commented May 5, 2022

@mr-bryn I'm glad it helped. I have same experience with this script.

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

No branches or pull requests

2 participants