In the extension.py you posted the try..except..finally is not executed as 
each of the try..except..finally lines is commented out.

Gary

On Wednesday, 16 April 2025 at 14:31:01 UTC+10 [email protected] wrote:

> I read several add'l values in from static files. Every once in a great 
> while, one of the files has extraneous character in it and it can't be read 
> as a float() and extensions.py crashes weewx. So after reading about 
> try/except/finally from several sources, I wanted to put the section where 
> it reads the float in a try statement, and if it fails, the exception 
> action is to assign a nominal float value for that weewx cycle, and write 
> it to the database. However when I put in the try: it immediately causes 
> weewx to exit, at all debug levels. 
> If you are more knowledgeable on Python 3 than I am, please look at my 
> extensions.py attachment and tell me how I need to restructure that code 
> block so it will work. Note, I have tried a couple different positions for 
> the initial try: block, no success. 
> Further note please, that this only applies to the lines where I 
> open '/home/pi/cputemp-opi5p.dat' and read the value into degf2 for it to 
> store it in 'extraTemp7'. Note further that this code is working for all 
> seven parameters being read and placed into the data, however, occasionally 
> (about once a week), somehow the system reads in erroneous data (such 
> as '94.8\x00' instead of '94.8')  and causes the python to exit. 
> I have looked at places where this data is created and cannot find any 
> evidence of that invalid value.
>
> Here is the pertinent part of the log at failure time:
> pi@PI4B1:~ $ systemctl status weewx
> ● weewx.service - WeeWX weather system
>      Loaded: loaded (/etc/systemd/system/weewx.service; enabled; vendor 
> preset: enabled)
>      Active: failed (Result: exit-code) since Tue 2025-04-15 16:00:16 CDT; 
> 4h 18min ago
>        Docs: https://weewx.com/docs
>     Process: 268425 ExecStart=/home/weewx/bin/weewxd 
> /home/weewx/weewx.conf (code=exited, status=1/FAILURE)
>    Main PID: 268425 (code=exited, status=1/FAILURE)
>         CPU: 4h 37min 25.648s
>
> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:     
> ****      self.engine.dispatchEvent(weewx.Event(weewx.NEW_ARCHIVE_RECORD,
> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:     
> ****    File "/home/weewx/bin/weewx/engine.py", line 245, in dispatchEvent
> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:     
> ****      callback(event)
> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:     
> ****    File "/home/weewx/bin/user/extensions.py", line 98, in 
> new_archive_packet
> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:     
> ****      degf2 = float(float(f.read()))                #this is OPI5P
> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:     
> ****  ValueError: could not convert string to float: '94.8\x00'
> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:     
> ****  Exiting.
> Apr 15 16:00:16 PI4B1 systemd[1]: weewx.service: Main process exited, 
> code=exited, status=1/FAILURE
> Apr 15 16:00:16 PI4B1 systemd[1]: weewx.service: Failed with result 
> 'exit-code'.
> Apr 15 16:00:16 PI4B1 systemd[1]: weewx.service: Consumed 4h 37min 25.648s 
> CPU time.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/weewx-user/62c17a5a-d508-4322-8458-c20941a0f45en%40googlegroups.com.

Reply via email to