Skip to content

Commit c631fc4

Browse files
authored
Add read ready flag to log check. (#46)
1 parent cf9d7da commit c631fc4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

rayvens/core/invocation.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def _check_kamel_output(self,
165165
# Start thread analyzing logs:
166166
reading_thread.start()
167167

168+
# Initiate the first read:
169+
reading_thread.read_flag.set()
170+
168171
success = False
169172
while True:
170173
# Log progress of kamel subprocess:
@@ -194,12 +197,14 @@ def _check_kamel_output(self,
194197
countdown -= 1
195198
if countdown == 0:
196199
break
200+
reading_thread.read_flag.set()
197201
time.sleep(0.01)
198202

199203
# Terminate log thread:
200204
if with_timeout:
201205
reading_thread.stop_flag.set()
202-
reading_thread.join()
206+
if success:
207+
reading_thread.join()
203208

204209
return success
205210

rayvens/core/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import os
1818
import random
19-
import time
2019
import threading
2120
from queue import Queue, Empty
2221

@@ -86,14 +85,16 @@ class LogThread(threading.Thread):
8685
def __init__(self, stdout):
8786
threading.Thread.__init__(self)
8887
self.stop_flag = threading.Event()
88+
self.read_flag = threading.Event()
8989
self.stdout = stdout
9090
self.queue = Queue()
9191

9292
def run(self):
9393
while not self.stop_flag.is_set():
94-
line = self.stdout.readline().decode("utf-8")
95-
self.queue.put(line.strip())
96-
time.sleep(0.1)
94+
if self.read_flag.is_set():
95+
line = self.stdout.readline().decode("utf-8")
96+
self.queue.put(line.strip())
97+
self.read_flag.clear()
9798

9899
print("[Logging thread] Kamel command logging terminated.")
99100

0 commit comments

Comments
 (0)