Skip to content

Commit

Permalink
str fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Aug 15, 2024
1 parent ca39782 commit b370ec5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
10 changes: 3 additions & 7 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,16 @@ def check_for_network(self) -> None:
def did_find_network() -> bool:
ipv4 = get_ip()

if ipv4 == "127.0.0.1" or ipv4 is None:
if ipv4 == "127.0.0.1" or ipv4 == "":
# no connection? Sound the alarm.
self.logger.warning("Unable to find a network...")
self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION)
return False
else:
return True

if utils.boolean_retry(did_find_network, retries=3, sleep_for=2):
ipv4: str = get_ip() or ""
else:
ipv4 = ""

self.ipv4 = ipv4
utils.boolean_retry(did_find_network, retries=3, sleep_for=2)
self.ipv4 = get_ip()

try:
with open("/sys/class/net/wlan0/address", "r") as f:
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/background_jobs/od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def add_post_read_callback(cls, function: Callable):

@property
def ir_led_on_and_rest_off_state(self) -> dict[pt.LedChannel, pt.LedIntensityValue]:
if config.getboolean("od_reading.config", "turn_off_leds_during_reading", fallback=True):
if config.getboolean("od_reading.config", "turn_off_leds_during_reading", fallback="True"):
return {
channel: (self.ir_led_intensity if channel == self.ir_channel else 0.0)
for channel in led_utils.ALL_LED_CHANNELS
Expand Down
5 changes: 2 additions & 3 deletions pioreactor/utils/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from queue import Queue
from threading import Thread
from typing import Generator
from typing import Optional


def cp_file_across_cluster(unit: str, localpath: str, remotepath: str, timeout: int = 5) -> None:
Expand Down Expand Up @@ -64,14 +63,14 @@ def is_reachable(address: str) -> bool:
return False


def get_ip() -> Optional[str]:
def get_ip() -> str:
# returns all ipv4s as comma-separated string
result = subprocess.run(["hostname", "-I"], stdout=subprocess.PIPE, text=True)
ipv4_addresses = result.stdout.strip().split()
if ipv4_addresses:
return ",".join(ipv4_addresses)
else:
return None
return ""


def discover_workers_on_network(terminate: bool = False) -> Generator[str, None, None]:
Expand Down

0 comments on commit b370ec5

Please sign in to comment.