Reapply "Mypy: Got passing on macos (#34591)" (#35126) (#35153)

* Mypy: Got passing on macos (#34591)

* Mypy: Got mypy passing on macos

* common/realtime.py refactor

* Mypy: mypy passing on darwin

* Refactor: Removed else: pass statement

* Refactor: Removed unnecessary check

* added xattr to pyproject

* loggerd: switched to xatter module

* loggerd: removed unused module in xattr_cache.py

* UV: update uv.lock

* Update system/athena/athenad.py



* athenad: fixed blank lines

* loggerd: refactor of xattr_cache

* cleanup

---------



* fix getxattr no attribute on macOS

* try fixing missing ENOATTR on Linux

---------

Co-authored-by: Andrei Radulescu <andi.radulescu@gmail.com>
Co-authored-by: BrainLess <116778989+BrainLessPea@users.noreply.github.com>
pull/35154/head
Maxime Desroches 2 days ago committed by GitHub
parent 2451d70408
commit 47ed90c6cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      common/realtime.py
  2. 7
      system/athena/athenad.py
  3. 11
      system/loggerd/xattr_cache.py

@ -1,6 +1,7 @@
"""Utilities for reading real time clocks and keeping soft real time constraints.""" """Utilities for reading real time clocks and keeping soft real time constraints."""
import gc import gc
import os import os
import sys
import time import time
from setproctitle import getproctitle from setproctitle import getproctitle
@ -28,13 +29,13 @@ class Priority:
def set_core_affinity(cores: list[int]) -> None: def set_core_affinity(cores: list[int]) -> None:
if not PC: if sys.platform == 'linux' and not PC:
os.sched_setaffinity(0, cores) os.sched_setaffinity(0, cores)
def config_realtime_process(cores: int | list[int], priority: int) -> None: def config_realtime_process(cores: int | list[int], priority: int) -> None:
gc.disable() gc.disable()
if not PC: if sys.platform == 'linux' and not PC:
os.sched_setscheduler(0, os.SCHED_FIFO, os.sched_param(priority)) os.sched_setscheduler(0, os.SCHED_FIFO, os.sched_param(priority))
c = cores if isinstance(cores, list) else [cores, ] c = cores if isinstance(cores, list) else [cores, ]
set_core_affinity(c) set_core_affinity(c)

@ -776,8 +776,11 @@ def ws_manage(ws: WebSocket, end_event: threading.Event) -> None:
# While not sending data, onroad, we can expect to time out in 7 + (7 * 2) = 21s # While not sending data, onroad, we can expect to time out in 7 + (7 * 2) = 21s
# offroad, we can expect to time out in 30 + (10 * 3) = 60s # offroad, we can expect to time out in 30 + (10 * 3) = 60s
# FIXME: TCP_USER_TIMEOUT is effectively 2x for some reason (32s), so it's mostly unused # FIXME: TCP_USER_TIMEOUT is effectively 2x for some reason (32s), so it's mostly unused
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, 16000 if onroad else 0) if sys.platform == 'linux':
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 7 if onroad else 30) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, 16000 if onroad else 0)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 7 if onroad else 30)
elif sys.platform == 'darwin':
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, 7 if onroad else 30)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 7 if onroad else 10) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 7 if onroad else 10)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 2 if onroad else 3) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 2 if onroad else 3)

@ -1,16 +1,17 @@
import os
import errno import errno
import xattr
_cached_attributes: dict[tuple, bytes | None] = {} _cached_attributes: dict[tuple, bytes | None] = {}
def getxattr(path: str, attr_name: str) -> bytes | None: def getxattr(path: str, attr_name: str) -> bytes | None:
key = (path, attr_name) key = (path, attr_name)
if key not in _cached_attributes: if key not in _cached_attributes:
try: try:
response = os.getxattr(path, attr_name) response = xattr.getxattr(path, attr_name)
except OSError as e: except OSError as e:
# ENODATA means attribute hasn't been set # ENODATA (Linux) or ENOATTR (macOS) means attribute hasn't been set
if e.errno == errno.ENODATA: if e.errno == errno.ENODATA or (hasattr(errno, 'ENOATTR') and e.errno == errno.ENOATTR):
response = None response = None
else: else:
raise raise
@ -19,4 +20,4 @@ def getxattr(path: str, attr_name: str) -> bytes | None:
def setxattr(path: str, attr_name: str, attr_value: bytes) -> None: def setxattr(path: str, attr_name: str, attr_value: bytes) -> None:
_cached_attributes.pop((path, attr_name), None) _cached_attributes.pop((path, attr_name), None)
return os.setxattr(path, attr_name, attr_value) xattr.setxattr(path, attr_name, attr_value)

Loading…
Cancel
Save