When I put the try: except: finally: back in, weewx never runs, I get the syslog entry of
*systemd[1]: weewx.service: Main process exited, code=exited, status=1/FAILURE* I have to comment out the try: except: finally: out of my extensions.py and it runs normal. I do not have a clue why, every once in a while (~once/week), a read statement picks up a text value from a temperature file and reads it in with extraneous characters. I've checked the source file (I have a history .log which has all the readings & their date/time in it) and that file at the point where that instance of the temperature is, does not have anything extra. On Wednesday, April 16, 2025 at 12:16:23 PM UTC-5 p q wrote: > The double float conversion looks wonky but wouldn't be the cause. You > shouldn't need to do > > degf2 = float(float(f.read())) > > You should be able to do degf2 = float(f.read()) > > The error message in your email says what the problem is - you're getting > 94.8\x00 as the string and it's failing to convert it to a float. Not > sure why your try catch doesn't work. I'd like to see what Gary's asking > for - put the try/catch in let's see the output. > > On Tue, Apr 15, 2025 at 11:48 PM Messy Potamia <messyp...@gmail.com> > wrote: > >> The error occurred before I added any try/except/finally. The error has >> to do with it trying to read something that has extraneous characters in >> it, and exiting because of it. So I wanted to add the error catching >> block...but when I do weewx refuses to run, and exits without any comment, >> even when weewx.conf has "debug = 2". As I wrote, the error happens about a >> couple time a month. I want to trap it so weewx will continue. >> >> On Wed, Apr 16, 2025 at 1:42 AM gjr80 <gjrod...@gmail.com> wrote: >> >>> Sorry, but I can't tell what code you are running other than to take at >>> face value what you post. There is nothing wrong with the >>> try..except..finally code as you posted it except for the comments. >>> Comments aside, the code you posted cannot have caused the error trace you >>> posted as the error trace shows the offending line as line 98 but the code >>> you posted has the offending code at line 100. Can you post the exact error >>> trace and the exact code that caused that error trace. >>> >>> Gary >>> On Wednesday, 16 April 2025 at 16:28:18 UTC+10 messyp...@gmail.com >>> wrote: >>> >>>> Of course they're commented out, when I uncomment [any] of them it >>>> exits / crashes. I need it to run until I can have someone tell me what's >>>> wrong / why the module crashes weewx. Duh. >>>> >>>> >>>> On Wed, Apr 16, 2025 at 12:13 AM gjr80 <gjrod...@gmail.com> wrote: >>>> >>>>> 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 messyp...@gmail.com >>>>> 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 a topic in the >>>>> Google Groups "weewx-user" group. >>>>> To unsubscribe from this topic, visit >>>>> https://groups.google.com/d/topic/weewx-user/cM4T6W4XjdA/unsubscribe. >>>>> To unsubscribe from this group and all its topics, send an email to >>>>> weewx-user+...@googlegroups.com. >>>>> To view this discussion visit >>>>> https://groups.google.com/d/msgid/weewx-user/62c17a5a-d508-4322-8458-c20941a0f45en%40googlegroups.com >>>>> >>>>> <https://groups.google.com/d/msgid/weewx-user/62c17a5a-d508-4322-8458-c20941a0f45en%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "weewx-user" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/weewx-user/cM4T6W4XjdA/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> weewx-user+...@googlegroups.com. >>> To view this discussion visit >>> https://groups.google.com/d/msgid/weewx-user/d9a3336a-129e-40df-b302-bff44a9eafdan%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/weewx-user/d9a3336a-129e-40df-b302-bff44a9eafdan%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> > 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 weewx-user+...@googlegroups.com. >> To view this discussion visit >> https://groups.google.com/d/msgid/weewx-user/CAB7-S776S8ECPE_2wE%3D46%3DUpVR2-rfrkWqooL_pzhJjcnFEF7Q%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/weewx-user/CAB7-S776S8ECPE_2wE%3D46%3DUpVR2-rfrkWqooL_pzhJjcnFEF7Q%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Peter Quinn > (415)794-2264 <(415)%20794-2264> > -- 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 weewx-user+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/weewx-user/2e747f7c-e5bd-49d3-aa0a-4e7e9e42905cn%40googlegroups.com.