Skip to content

Commit

Permalink
update executable monitor file
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaodong Li committed Jul 3, 2023
1 parent 31f4360 commit 170941c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 15 additions & 13 deletions executable-monitor/executable-monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,28 @@
logging.info(f"Storing logs in: {log_dir}")
logging.info(f"Timeout (seconds): {args.timeout_seconds}")

exe = subprocess.Popen([exe_abs_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)

cur_time_seconds = time.time()
timeout_time_seconds = cur_time_seconds + args.timeout_seconds
# Initialize values
timeout_occurred = False

exe_exit_status = None
exe_exitted = False

success_line_found = False
cur_line_ouput = 1
wait_for_exit = args.success_exit_status is not None

wait_for_exit = args.success_exit_status is not None
# Launch the executable
exe = subprocess.Popen([exe_abs_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)

cur_time_seconds = time.time()
timeout_time_seconds = cur_time_seconds + args.timeout_seconds

logging.info("START OF DEVICE OUTPUT\n")

while not (timeout_occurred or exe_exitted or (not wait_for_exit and success_line_found)):

# Check if executable exitted
exe_exit_status = exe.poll()
if exe_exit_status is not None:
exe_exitted = True

# Read executable's stdout and write to stdout and logfile
exe_stdout_line = exe.stdout.readline()
logging.info(exe_stdout_line)
Expand All @@ -99,16 +103,14 @@
if args.success_line is not None and args.success_line in exe_stdout_line:
success_line_found = True

# Check if executable exitted
exe_exit_status = exe.poll()
if exe_exit_status is not None:
exe_exitted = True

# Check for timeout
cur_time_seconds = time.time()
if cur_time_seconds >= timeout_time_seconds:
timeout_occurred = True

# Sleep for a short duration between loops to not steal all system resources
time.sleep(.1)

if not exe_exitted:
exe.kill()

Expand Down
4 changes: 3 additions & 1 deletion localhost-echo-server/local_echo_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import asyncio
import logging
import os
Expand All @@ -14,7 +16,7 @@ async def echo_handler(reader, writer):
writer.close()

if __name__ == '__main__':
parser = ArgumentParser(description='Localhost MQTT broker.')
parser = ArgumentParser(description='Localhost Echo server.')
parser.add_argument('--port_number',
type=int,
required=True,
Expand Down

0 comments on commit 170941c

Please sign in to comment.