Skip to content

Commit

Permalink
py: fix jobserver-style fifo
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Dec 24, 2023
1 parent 762b8d5 commit bcc75be
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions py/src/gnumake_tokenpool/tokenpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(
self._fdRead = None
self._fdReadDup = None
self._fdWrite = None
self._fifoPath = None
self._fdFifo = None
self._maxJobs = None
self._maxLoad = None
self._fileRead = None
Expand Down Expand Up @@ -66,13 +68,15 @@ def __init__(
# parse

for flag in re.split(r"\s+", makeFlags):
m = (
re.fullmatch(r"--jobserver-auth=(\d+),(\d+)", flag) or
re.fullmatch(r"--jobserver-fds=(\d+),(\d+)", flag)
)
m = re.fullmatch(r"--jobserver-(?:auth|fds)=(?:(\d+),(\d+)|fifo:(.*))", flag)
if m:
self._fdRead = int(m.group(1))
self._fdWrite = int(m.group(2))
if m.group(1) and m.group(2):
self._fdRead = int(m.group(1))
self._fdWrite = int(m.group(2))
self._log(f"init: found jobserver pipes: {self._fdRead},{self._fdWrite}")
elif m.group(3):
self._fifoPath = m.group(3)
self._log(f"init: found jobserver fifo: {self._fifoPath}")
continue
m = re.fullmatch(r"-j(\d+)", flag)
if m:
Expand All @@ -92,6 +96,11 @@ def __init__(
self._fileWrite = open(named_pipes[1], "w")
self._fdRead = self._fileRead.buffer.fileno()
self._fdWrite = self._fileWrite.buffer.fileno()
elif self._fifoPath:
self._log(f"init: using jobserver fifo: {self._fifoPath}")
self._fdFifo = os.open(self._fifoPath, os.O_RDWR)
self._fdRead = self._fdFifo
self._fdWrite = self._fdFifo

if max_jobs:
self._log(f"init: using max_jobs: {max_jobs}")
Expand Down Expand Up @@ -157,6 +166,11 @@ def __init__(
self._log("init: test ok")


def __del__(self):
if self._fdFifo:
os.close(self._fdFifo)


@property
def maxJobs(self) -> int or None:
return self._maxJobs
Expand Down

0 comments on commit bcc75be

Please sign in to comment.