os_uptime incorrect on 4.0.0/python3.7 on macos

49 views
Skip to first unread message

Graham Eddy

unread,
May 10, 2020, 9:30:27 PM5/10/20
to weewx-de...@googlegroups.com
having moved to 4.0.0/python3.7 last night i see a couple of anomalies i did not notice in testing.
the following one is mainly cosmetic but i think i have a fix for it

uptime_os (in the “About Station” part of Season skin) presently reports obviously incorrect value:
Server uptime
18393 days, 0 hours, 10 minutes
WeeWX uptime
0 days, 8 hours, 35 minutes
WeeWX version
4.0.0

looking in weewx/station.py:
try:
    # For MacOs:
    from Quartz.QuartzCore import CACurrentMediaTime
    os_uptime_secs = CACurrentMediaTime()
except ImportError:

a simple test shows the ImportError option is being exercised:
from Quartz.QuartzCore import CACurrentMediaTime
os_uptime_secs = CACurrentMediaTime()
print(os_uptime_secs)
print(os_uptime_secs/float(3600))
and python3.7 (from macports) gives
Traceback (most recent call last):
  File "/Users/graham/a.py", line 1, in <module>
    from Quartz.QuartzCore import CACurrentMediaTime
ModuleNotFoundError: No module named 'Quartz'
but python2.7 (from macos platform), where 3.9.1 worked fine, gives
815589.697895
226.55269386

reading weewx/station.py, the consequence of following the Import exception is that os_uptime_secs remains unset i.e. a garbage value

unfortunately i can’t install the missing module Quartz under python3.7:
sudo python3.7 -m pip install Quartz
Password:
...
Collecting Quartz
  Downloading quartz-0.0.1.dev0.tar.gz (217 kB)
     |████████████████████████████████| 217 kB 694 kB/s 
    ERROR: Command errored out with exit status 1:
...
      File "/private/tmp/pip-install-36vqysll/Quartz/setup.py", line 7, in read_dependencies
        with open(req_file) as req:
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

consulting doctor google, i came across module uptime, which i installed using python3.7 -m pip.
purportedly  it is cross-platform including linux and linux-like. it seems to give the correct result for macos and, if it really is cross-platform, could simplify weewx/station.py by avoiding testing for each platform itself
import uptime
secs = uptime.uptime()
print(secs)
print(secs/float(3600))
gives good values on my mac server:
817999.84659
227.22217960833333
but it is a dependency on another external module

g-eddy

Tom Keffer

unread,
May 10, 2020, 9:40:00 PM5/10/20
to weewx-development
It is a new dependency, which is unacceptable, especially for such a minor feature.

Looking through the source code for 'uptime', on Python 2 it uses the module MacOS, but under Python 3, it relies on custom ctypes code.

If we can't find a way around this, we're just going to have to disable the Mac system uptime tag.

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/8F61A89F-8268-464F-96EA-245700B03B62%40gmail.com.

Greg Troxel

unread,
May 11, 2020, 8:24:28 AM5/11/20
to Tom Keffer, weewx-development
Tom Keffer <tke...@gmail.com> writes:

> If we can't find a way around this, we're just going to have to disable the
> Mac system uptime tag.

Perhaps initialize uptime, before any code is run, to None to mean "we
don't know", and then just omit reading/using it when None, which could
handle systems that can't get uptime in general.

Tom Keffer

unread,
May 11, 2020, 8:30:45 AM5/11/20
to weewx-development
Exactly. A PR from someone is welcome.

-tk
Reply all
Reply to author
Forward
0 new messages