Skip to content

Commit

Permalink
fix(cli): Fix issue when running sysctl through USR2 in macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
msbrogli committed Feb 16, 2024
1 parent b33f03e commit 06980f3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions hathor/cli/run_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@


@contextmanager
def temp_fifo(filename: str, tempdir: str | None) -> Iterator[TextIO]:
def temp_fifo(filename: str, tempdir: str | None) -> Iterator[None]:
"""Context Manager for creating named pipes."""
mkfifo = getattr(os, 'mkfifo', None)
if mkfifo is None:
raise AttributeError('mkfifo is not available')

mkfifo(filename, mode=0o666)
fp = open(filename, 'r')
try:
yield fp
yield None
finally:
fp.close()
os.unlink(filename)
if tempdir is not None:
os.rmdir(tempdir)
Expand Down Expand Up @@ -305,9 +303,15 @@ def run_sysctl_from_signal(self) -> None:
self.log.warn('[USR2] Pipe already exists.', pipe=filename)
return

with temp_fifo(filename, tempdir) as fp:
with temp_fifo(filename, tempdir):
self.log.warn('[USR2] Main loop paused, awaiting command to proceed.', pipe=filename)
lines = fp.readlines()

fp = open(filename, 'r')
try:
lines = fp.readlines()
finally:
fp.close()

for cmd in lines:
cmd = cmd.strip()
self.log.warn('[USR2] Command received ', cmd=cmd)
Expand Down

0 comments on commit 06980f3

Please sign in to comment.