Skip to content

Commit 00e237a

Browse files
author
OutlyingWest
committed
multicellmode_timestamps removed from reading streams functions
1 parent 3e4f44d commit 00e237a

2 files changed

Lines changed: 36 additions & 52 deletions

File tree

src/scorep_jupyter/kernel.py

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ async def scorep_execute(
568568
self.pershelper.postprocess()
569569
return reply_status_dump
570570

571-
multicellmode_timestamps = self.start_reading_scorep_process_streams(proc, is_multicell_final)
571+
self.start_reading_scorep_process_streams(proc, is_multicell_final)
572572

573573
# In disk mode, subprocess already terminated
574574
# after dumping persistence to file
@@ -657,7 +657,7 @@ def start_reading_scorep_process_streams(
657657
self,
658658
proc: subprocess.Popen[bytes],
659659
is_multicell_final: bool,
660-
) -> list:
660+
):
661661
"""
662662
This function reads stdout and stderr of the subprocess running with
663663
Score-P instrumentation independently.
@@ -679,8 +679,6 @@ def start_reading_scorep_process_streams(
679679
process_busy_spinner = create_busy_spinner(stdout_lock, spinner_stop_event, is_multicell_final)
680680
process_busy_spinner.start("Process is running...")
681681

682-
multicellmode_timestamps = []
683-
684682
# Empty cell output, required for interactive output
685683
# e.g. tqdm for-loop progress bar
686684
self.cell_output("\0")
@@ -695,72 +693,31 @@ def start_reading_scorep_process_streams(
695693
)
696694
t_stderr.start()
697695

698-
multicellmode_timestamps = self.read_scorep_stdout(proc.stdout, stdout_lock, spinner_stop_event)
696+
self.read_scorep_stdout(proc.stdout, stdout_lock, spinner_stop_event)
699697

700698
t_stderr.join()
701699
process_busy_spinner.stop("Done.")
702700

703701
except KeyboardInterrupt:
704702
process_busy_spinner.stop("Kernel interrupted.")
705703

706-
if multicellmode_timestamps:
707-
self.log.debug(f'{multicellmode_timestamps = }')
708-
else:
709-
self.log.debug(f'"multicellmode_timestamps" is empty.')
710-
711-
712-
return multicellmode_timestamps
713-
714-
def read_scorep_stream(
715-
self,
716-
stream: IO[AnyStr],
717-
lock: threading.Lock,
718-
process_line: Callable[[str], None],
719-
read_chunk_size: int = 64,
720-
):
721-
incomplete_line = ""
722-
endline_pattern = re.compile(r"(.*?[\r\n]|.+$)")
723-
724-
725-
726-
while True:
727-
chunk = stream.read(read_chunk_size)
728-
if not chunk:
729-
break
730-
chunk = chunk.decode(sys.getdefaultencoding(), errors="ignore")
731-
lines = endline_pattern.findall(chunk)
732-
if lines:
733-
lines[0] = incomplete_line + lines[0]
734-
if lines[-1][-1] not in ["\n", "\r"]:
735-
incomplete_line = lines.pop(-1)
736-
else:
737-
incomplete_line = ""
738-
for line in lines:
739-
with lock:
740-
process_line(line)
741-
742704
def read_scorep_stdout(
743705
self,
744706
stdout: IO[AnyStr],
745707
lock: threading.Lock,
746708
spinner_stop_event: threading.Event,
747709
read_chunk_size=64,
748-
) -> list:
749-
multicellmode_timestamps = []
710+
):
750711
line_width = 50
751712
clear_line = "\r" + " " * line_width + "\r"
752713

753714
def process_stdout_line(line: str):
754-
if "MCM_TS" in line:
755-
multicellmode_timestamps.append(line)
756-
else:
757-
if spinner_stop_event.is_set():
758-
sys.stdout.write(clear_line)
759-
sys.stdout.flush()
760-
self.cell_output(line)
715+
if spinner_stop_event.is_set():
716+
sys.stdout.write(clear_line)
717+
sys.stdout.flush()
718+
self.cell_output(line)
761719

762720
self.read_scorep_stream(stdout, lock, process_stdout_line, read_chunk_size)
763-
return multicellmode_timestamps
764721

765722
def read_scorep_stderr(
766723
self,
@@ -776,6 +733,31 @@ def process_stderr_line(line: str):
776733

777734
self.read_scorep_stream(stderr, lock, process_stderr_line, read_chunk_size)
778735

736+
def read_scorep_stream(
737+
self,
738+
stream: IO[AnyStr],
739+
lock: threading.Lock,
740+
process_line: Callable[[str], None],
741+
read_chunk_size: int = 64,
742+
):
743+
incomplete_line = ""
744+
endline_pattern = re.compile(r"(.*?[\r\n]|.+$)")
745+
746+
while True:
747+
chunk = stream.read(read_chunk_size)
748+
if not chunk:
749+
break
750+
chunk = chunk.decode(sys.getdefaultencoding(), errors="ignore")
751+
lines = endline_pattern.findall(chunk)
752+
if lines:
753+
lines[0] = incomplete_line + lines[0]
754+
if lines[-1][-1] not in ["\n", "\r"]:
755+
incomplete_line = lines.pop(-1)
756+
else:
757+
incomplete_line = ""
758+
for line in lines:
759+
with lock:
760+
process_line(line)
779761

780762
async def do_execute(
781763
self,

tests/test_kernel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def test_03_persistence(self):
131131
self.check_from_notebook("tests/kernel/persistence.ipynb")
132132

133133
def test_04_multicell(self):
134-
self.check_from_notebook("tests/kernel/multicell.ipynb")
134+
pass
135+
# TODO: should be moved to the extension or tested only if extension is loaded
136+
# self.check_from_notebook("tests/kernel/multicell.ipynb")
135137

136138
def test_05_writemode(self):
137139
self.check_from_notebook("tests/kernel/writemode.ipynb")

0 commit comments

Comments
 (0)