@@ -802,10 +802,11 @@ async def scorep_execute(
802802 # e.g. tqdm for-loop progress bar
803803 self .cell_output ("\0 " )
804804
805- process_busy_spinner = BusySpinner ()
805+ stdout_lock = threading .Lock ()
806+ process_busy_spinner = BusySpinner (stdout_lock )
806807 process_busy_spinner .start ('Process is running...' )
807808
808- multicellmode_timestamps = self .read_scorep_process_pipe (proc )
809+ multicellmode_timestamps = self .read_scorep_process_pipe (proc , stdout_lock )
809810
810811 process_busy_spinner .stop ()
811812
@@ -962,11 +963,12 @@ async def scorep_execute(
962963 return self .standard_reply ()
963964
964965
965- def read_scorep_process_pipe (self , proc : subprocess .Popen [bytes ]) -> list :
966+ def read_scorep_process_pipe (self , proc : subprocess .Popen [bytes ], stdout_lock : threading . Lock ) -> list :
966967 """
967968 Reads and processes the output of a subprocess running with Score-P instrumentation.
968969 Args:
969970 proc (subprocess.Popen[bytes]): The subprocess whose output is being read.
971+ stdout_lock (threading.Lock): Lock to avoid output overlapping
970972
971973 Returns:
972974 list: A list of decoded strings containing "MCM_TS" timestamps.
@@ -977,6 +979,9 @@ def read_scorep_process_pipe(self, proc: subprocess.Popen[bytes]) -> list:
977979 sel .register (proc .stdout , selectors .EVENT_READ )
978980 sel .register (proc .stderr , selectors .EVENT_READ )
979981
982+ line_width = 50
983+ clear_line = "\r " + " " * line_width + "\r "
984+
980985 while True :
981986 # Select between stdout and stderr
982987 for key , val in sel .select ():
@@ -988,11 +993,15 @@ def read_scorep_process_pipe(self, proc: subprocess.Popen[bytes]) -> list:
988993 decoded_line = line .decode (sys .getdefaultencoding (), errors = 'ignore' )
989994
990995 if key .fileobj is proc .stderr :
991- self .log .warning (f'{ decoded_line .strip ()} ' )
996+ with stdout_lock :
997+ self .log .warning (f'{ decoded_line .strip ()} ' )
992998 elif 'MCM_TS' in decoded_line :
993999 multicellmode_timestamps .append (decoded_line )
9941000 else :
995- self .cell_output (decoded_line )
1001+ with stdout_lock :
1002+ sys .stdout .write (clear_line )
1003+ sys .stdout .flush ()
1004+ self .cell_output (decoded_line )
9961005
9971006 # If both stdout and stderr empty -> out of loop
9981007 if not sel .get_map ():
0 commit comments