I am trying to get a python program to continuously run until a certain aws log is registered and printed. It is supposed to:
- Run indefinitely even if no events happen
- List whatever events occurs (in my case a log stating that the task is finished)
- Stop running
the python command looks like this: python3 watch_logs.py <log-source> --start=15:00:00
The logs are working fine, and the python script can print them out between certain time frames as long as they already exist. The program works by taking a continuously running task which prints events to the log file, and the python script should filter out events I am looking for and print them.
But, when I run the script, it wont print the event even if I can see the log entry appear in the file. If i kill the process and run it again using the same timestamp, it will find the log entry and end the script like it should.
the code is fairly short:
logs = get_log_events(
log_group=log_group,
start_time=start_time,
end_time=end_time
)
while True:
for event in logs:
print(event['message'].rstrip())
sys.exit("Task complete")
Any insight why this is happening would help a lot. I am fairly new to python
logsin that code? This example is not complete.while True:- 2. logs is a collection with just one element: something would be printed, program would terminate. - 3. logs is a generator function that did not yet generate anything: your program would wait until something is generated. - it looks like the first case is true, and logs is just an empty collection.logsrefers to a connection to an aws logging service. It vomits out thousands of events every minute. The code is built to connect to it, filter what I need, and print out the filtered items. I added the snippet that defines this. It might be useful.