Skip to content

Commit

Permalink
失败的尝试,要么读不全,要么读重复
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuJiewenTT committed Jan 31, 2024
1 parent 5eb10bb commit c4e542d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
venv
keep_local
.idea
__pycache__
Empty file.
16 changes: 14 additions & 2 deletions src/CBJQ_SS_FrontEnd_tk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def execAction_threading(self, **kwargs):
thread.start()

def execAction(self, **kwargs):

def waitlast():
nonlocal output
output = sp.stdout.readline()

self.displayLog_text.insertAndScrollToEnd('[+]' + '运行前报告' + '=' * 15)
self.displayLog_text.insertAndScrollToEnd(kwargs)
launch_args = []
Expand All @@ -220,15 +225,22 @@ def execAction(self, **kwargs):
with subprocess.Popen(launch_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8') as sp:
self.displayLog_text.insertAndScrollToEnd(f'sp.pid: {sp.pid}')
self.displayLog_text.insertAndScrollToEnd('[+]' + '运行报告' + '-' * 15)
while sp.poll() is None:
thread = threading.Thread(target=waitlast)
while True:
# print('to read')
# output = sp.communicate(timeout=1)[0]
output = sp.stdout.readline()
if sp.poll() is not None:
thread.start()
if not thread.is_alive():
break
else:
output = sp.stdout.readline()
# print(f'[stdout]: {i}', end='')
# self.displayLog_text.insert('end', i)
# self.displayLog_text.yview_moveto(1)
self.displayLog_text.insertAndScrollToEnd(output, end='') # instance method
# self.displayLog_text.update()
thread.join(timeout=3)
print('')
self.displayLog_text.insertAndScrollToEnd('[-]' + '运行后报告' + '-' * 15)
self.displayLog_text.insertAndScrollToEnd('[-]' + '' + '=' * 15)
Expand Down

0 comments on commit c4e542d

Please sign in to comment.