Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions leads/comm/prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ def _register_process(self, *args, **kwargs) -> None:
:param kwargs: kwargs passed to `run()`
:exception RuntimeError: duplicated registration
"""
self._lock.acquire()
if self._main_thread:
raise RuntimeError("A service can only run once")
try:
with self._lock:
self._main_thread = _Thread(name=f"service{hash(self)}", target=self._run, daemon=True, args=args,
kwargs=kwargs)
finally:
self._lock.release()

def _parallel_run(self, *args, **kwargs) -> None:
"""
Expand Down
5 changes: 1 addition & 4 deletions leads/dt/odometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ def __init__(self) -> None:

@_override
def write(self, payload: float) -> None:
self._lock.acquire()
try:
with self._lock:
super().write(payload)
finally:
self._lock.release()
5 changes: 1 addition & 4 deletions leads/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ def format(self, msg: str, font: int, color: int | None, background: int | None)
return f"\033[{font}{f";{color}" if color else ""}{f";{background + 10}" if background else ""}m{msg}\033[0m"

def print(self, msg: str, level: int) -> None:
self._lock.acquire()
try:
with self._lock:
if self._debug_level <= level:
print(msg)
finally:
self._lock.release()

def info(self, *msg: str, sep: str = " ", end: str = "\n",
f: tuple[int, int | None, int | None] = (REGULAR, None, None)) -> None:
Expand Down
5 changes: 1 addition & 4 deletions leads/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ def active(self) -> bool:

@active.setter
def active(self, active: bool) -> None:
self._lock.acquire()
try:
with self._lock:
self._active = active
finally:
self._lock.release()


_thread_flags: _ThreadFlags = _ThreadFlags()
Expand Down
5 changes: 1 addition & 4 deletions leads_comm_serial/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ def _establish_connection_no_lock(self, serial: _Serial) -> SerialConnection:
return self._establish_connection_no_lock(serial)

def establish_connection(self, serial: _Serial) -> SerialConnection:
_lock.acquire()
try:
with _lock:
return self._establish_connection_no_lock(serial)
finally:
_lock.release()


_instances: dict[AutoIdentity, str | None] = {}
Expand Down