Skip to content

Commit

Permalink
Fix javascript stdout not appearing in Python on notebooks
Browse files Browse the repository at this point in the history
Reverts change #103 as sys.stdout.fileno doesn't exist on Colab notebooks; also fix color outputs in notebooks
  • Loading branch information
extremeheat authored Dec 13, 2023
1 parent 49c0a58 commit 3b0d69c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/javascript/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def is_notebook():

shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
return True
return True # Jupyter
elif shell == "TerminalInteractiveShell":
return True # IPython


# Modified stdout
Expand All @@ -41,7 +43,7 @@ def supports_color():
is_a_tty = hasattr(sys.stdout, "isatty") and sys.stdout.isatty()
if 'idlelib.run' in sys.modules:
return False
if notebook and not modified_stdout:
if is_notebook():
return True
return supported_platform and is_a_tty

Expand Down Expand Up @@ -179,7 +181,7 @@ def com_io():
# FIXME untested
def stdout_read():
while proc.poll() is None:
os.write(sys.stdout.fileno(), proc.stdout.readline())
print(proc.stdout.readline().decode("utf-8"))


def start():
Expand Down

0 comments on commit 3b0d69c

Please sign in to comment.