Skip to content

Commit c4514d1

Browse files
committed
suppress/restore stdout in jupyter
1 parent 7d3445b commit c4514d1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pyvcell/vcml/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
field_data_refs,
2727
load_antimony_file,
2828
load_antimony_str,
29-
load_sbml_url,
3029
load_sbml_file,
3130
load_sbml_str,
32-
load_vcml_url,
31+
load_sbml_url,
3332
load_vcml_file,
3433
load_vcml_str,
34+
load_vcml_url,
35+
restore_stdout,
36+
suppress_stdout,
3537
to_antimony_str,
3638
to_sbml_str,
3739
to_vcml_str,
3840
update_biomodel,
3941
write_antimony_file,
4042
write_sbml_file,
4143
write_vcml_file,
42-
suppress_stdout,
43-
restore_stdout,
4444
)
4545
from pyvcell.vcml.vcml_reader import VcmlReader
4646
from pyvcell.vcml.vcml_simulation import simulate
@@ -92,4 +92,6 @@
9292
"Field",
9393
"load_vcml_url",
9494
"load_sbml_url",
95+
"suppress_stdout",
96+
"restore_stdout",
9597
]

pyvcell/vcml/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,14 @@ def refresh_biomodel(bio_model: Biomodel) -> Biomodel:
326326
return VcmlReader.biomodel_from_file(vcml_path=vcml_path)
327327

328328

329-
def suppress_stdout():
329+
def suppress_stdout() -> None:
330330
sys.stdout.flush() # Ensure all Python-level stdout is flushed
331331
devnull = os.open(os.devnull, os.O_WRONLY)
332332
os.dup2(devnull, sys.stdout.fileno())
333333

334334

335-
def restore_stdout():
335+
def restore_stdout() -> None:
336336
sys.stdout.flush()
337+
if sys.__stdout__ is None:
338+
return
337339
os.dup2(sys.__stdout__.fileno(), sys.stdout.fileno())

0 commit comments

Comments
 (0)