Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: print_log tasks keep reading after vm end #459

Merged
merged 1 commit into from
Nov 17, 2023
Merged
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
23 changes: 11 additions & 12 deletions src/aleph/vm/hypervisors/firecracker/microvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,31 +360,30 @@ async def print_logs(self):
while not self.proc:
await asyncio.sleep(0.01) # Todo: Use signal here
while True:
stdout = await self.proc.stdout.readline()
line = await self.proc.stdout.readline()
if not line: # EOF, FD is closed nothing more will come
return
for queue in self.log_queues:
if queue.full():
logger.warning("Log queue is full")
else:
await queue.put(("stdout", stdout))
if stdout:
print(stdout.decode().strip())
else:
await asyncio.sleep(0.001)
await queue.put(("stdout", line))
print(self, line.decode().strip())

async def print_logs_stderr(self):
while not self.proc:
await asyncio.sleep(0.01) # Todo: Use signal here
while True:
stderr = await self.proc.stderr.readline()
line = await self.proc.stderr.readline()
if not line: # EOF, FD is closed nothing more will come
return
for queue in self.log_queues:
if queue.full():
logger.warning("Log queue is full")
else:
await queue.put(("stderr", stderr))
if stderr:
print(stderr.decode().strip())
else:
await asyncio.sleep(0.001)
await queue.put(("stderr", line))
await queue.put(("stderr", line))
print(self, line.decode().strip(), file=sys.stderr)

def start_printing_logs(self) -> tuple[Task, Task]:
loop = asyncio.get_running_loop()
Expand Down
Loading